fix(09): theme PUT uses "updatedAt" not updated_at (Better Auth column is camelCase)

Verified via psql that the user table has quoted camelCase columns from
Better Auth ("updatedAt", "createdAt", "emailVerified"). The original
route comment claimed app/api/settings/profile as precedent — that route
is ALSO broken with the same bug; only app/api/me/timezone got it right.
Aligning theme route with the timezone precedent.
This commit is contained in:
lorentz 2026-05-10 22:49:47 -04:00
parent 2a3e89c753
commit 041fb164e3

View file

@ -12,9 +12,9 @@ import { postgresClient } from '@/lib/services/postgres-client';
// Validation: the input theme must be one of: 'light', 'dark', 'system'.
// Anything else is rejected with 400 before touching the database.
//
// NOTE: The UPDATE statement uses `updated_at` (snake_case, unquoted) — the
// actual column in migration 012_create_auth_tables.sql. This matches the
// working precedent in app/api/settings/profile/route.ts (not the timezone route).
// NOTE: The UPDATE statement uses `"updatedAt"` (quoted camelCase) — that is
// the actual column name in the Better Auth `"user"` table (verified via psql).
// Matches the working precedent in app/api/me/timezone/route.ts.
const ALLOWED_THEMES = new Set(['light', 'dark', 'system'] as const);
@ -74,9 +74,9 @@ export async function PUT(request: NextRequest): Promise<NextResponse> {
try {
// Authoritative write target: session.user.id. NO userId from body.
// updated_at is unquoted snake_case — matches migration 012 schema.
// "updatedAt" is quoted camelCase — matches Better Auth schema (verified).
const result = await postgresClient.query<{ theme: string }>(
'UPDATE "user" SET theme = $1, updated_at = NOW() WHERE id = $2 RETURNING theme',
'UPDATE "user" SET theme = $1, "updatedAt" = NOW() WHERE id = $2 RETURNING theme',
[candidate, session!.user.id],
);
if (result.rowCount === 0) {