diff --git a/app/api/me/theme/route.ts b/app/api/me/theme/route.ts index f50a96a..de73ffd 100644 --- a/app/api/me/theme/route.ts +++ b/app/api/me/theme/route.ts @@ -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 { 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) {