| 1 | 'use server' |
| 2 | |
| 3 | import { eq } from 'drizzle-orm' |
| 4 | import { z } |
| 5 | import { actionClient } |
| 6 | import { getSession } |
| 7 | import { db } |
| 8 | import { users } |
| 9 | |
| 10 | const timezoneSchema = z |
| 11 | .string() |
| 12 | .min(1) |
| 13 | .max(64) |
| 14 | .refine((tz) |
| 15 | try { |
| 16 | new Intl.DateTimeFormat |
| 17 | return true |
| 18 | } catch { |
| 19 | return false |
| 20 | } |
| 21 | }, 'Invalid IANA timezone') |
| 22 | |
| 23 | // Auth-only (not authedActionClient): a freshly signed-up user has no active |
| 24 | // organization yet, but still needs their timezone recorded. |
| 25 | export const updateTimezoneAction = |
| 26 | .inputSchema(z.object |
| 27 | .action(async ( |
| 28 | const session = |
| 29 | if (!session) |
| 30 | throw new Error( |
| 31 | } |
| 32 | await db |
| 33 | .update(users) |
| 34 | .set({ timezone |
| 35 | .where(eq(users |
| 36 | }) |