Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

feat: start new accounts in the device timezone (#3744)

Amruth Pillai1833d1fb2a46
diff --git a/apps/web/src/libs/auth/client.ts b/apps/web/src/libs/auth/client.ts
index 5ef3fd765..ea6d899dd 100644
--- a/apps/web/src/libs/auth/client.ts
+++ b/apps/web/src/libs/auth/client.ts
@@ -14,6 +14,12 @@ import { createAuthClient } from "better-auth/react";
import { authSearchSchema } from "@/features/auth/redirect";
export const authClient = createAuthClient({
+ // New accounts start in the device timezone instead of UTC. Social sign-in carries this into the
+ // OAuth state on the server; email and guest creation read it directly. A static header merges
+ // with per-call options, unlike a global onRequest that a per-call one would replace.
+ fetchOptions: {
+ headers: { "x-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC" },
+ },
plugins: [
dashClient(),
adminClient(),
diff --git a/docs/contributing/career-platform.mdx b/docs/contributing/career-platform.mdx
index 78a51331b..3775526c5 100644
--- a/docs/contributing/career-platform.mdx
+++ b/docs/contributing/career-platform.mdx
@@ -39,7 +39,7 @@ The coach prioritizes the resume and letter versions recorded as sent for that a
- **Facts** show where they came from and their correction history. **Correct** keeps the original in the history and marks stories that use the fact for review. Switching a fact off stops the coach from reading it; a switched-off fact can't back a story. Facts private to one application are used only when coaching for it, until you choose **Use for all applications**.
- **Forget** removes the fact after a six-second undo, unlinks it from stories and saved items, and keeps a content-free marker so it isn't re-extracted from the same source. The original resume, message or file isn't changed.
- **STARR stories** contain Situation, Task, Action, Result and Reflection with the facts that back them. Situation, Task and Action are required; leave Result and Reflection blank until you can support them.
-- **Preferences** (target roles, places, what matters, minimum base salary, office days, notice period) feed discovery, the match chips on new roles, Fit's requirement checks and Offers. All times in Career are shown in the account's timezone, set in **Settings → Preferences** (UTC until changed).
+- **Preferences** (target roles, places, what matters, minimum base salary, office days, notice period) feed discovery, the match chips on new roles, Fit's requirement checks and Offers. All times in Career are shown in the account's timezone, set in **Settings → Preferences** (the device timezone for new accounts; existing accounts that never changed it stay on UTC).
Every AI action shows a privacy line naming what is sent and to which connection. In **Coach**, the context chips decide what goes with the next message: **Applications** (summaries of your applications), **Knowledge** (switched-on facts, stories and preferences) and **Web research** (off by default; search terms go to your web search service). Choices persist per conversation. Turning context off can't recall information already sent to a provider. Comparing offers and editing Knowledge send nothing.
diff --git a/docs/guides/changing-appearance-and-language.mdx b/docs/guides/changing-appearance-and-language.mdx
index 47787e288..bcc85c50c 100644
--- a/docs/guides/changing-appearance-and-language.mdx
+++ b/docs/guides/changing-appearance-and-language.mdx
@@ -65,7 +65,7 @@ The interface language doesn't translate your resume. Each resume has its own **
## Set your timezone
-Go to **Settings → Preferences** and pick your timezone under **Timezone**. Interview times, reminders and schedules in Career use it. New accounts start on UTC; when your device is set to another timezone, **Use this device's timezone** switches to it in one step. The change is saved at once.
+Go to **Settings → Preferences** and pick your timezone under **Timezone**. Interview times, reminders and schedules in Career use it. New accounts start in your device's timezone; existing accounts that never changed it stay on UTC. **Use this device's timezone** switches to it in one step, and the change is saved at once.
## Turn off haptic feedback
diff --git a/packages/auth/src/config.test.ts b/packages/auth/src/config.test.ts
index 7524259ea..6604da4e5 100644
--- a/packages/auth/src/config.test.ts
+++ b/packages/auth/src/config.test.ts
@@ -22,6 +22,48 @@ describe("session freshness", () => {
});
});
+describe("new account timezone", () => {
+ const createBefore = auth.options.databaseHooks?.user?.create?.before;
+
+ if (!createBefore) throw new Error("Missing user create hook");
+
+ const now = new Date();
+ const newUser = {
+ id: "new-user",
+ email: "[email protected]",
+ emailVerified: false,
+ name: "New user",
+ createdAt: now,
+ updatedAt: now,
+ };
+ const contextWith = (headers: Record<string, string>) => ({ headers: new Headers(headers) }) as never;
+
+ it("starts a new account in the device timezone sent by the client", async () => {
+ await expect(createBefore(newUser, contextWith({ "x-client-timezone": "Europe/Berlin" }))).resolves.toEqual({
+ data: expect.objectContaining({ timezone: "Europe/Berlin" }),
+ });
+ });
+
+ it.each([{}, { "x-client-timezone": "Not/A_Timezone" }])(
+ "keeps the database default when the header is missing or invalid",
+ async (headers) => {
+ await expect(createBefore(newUser, contextWith(headers))).resolves.toBeUndefined();
+ },
+ );
+
+ it("gives a guest both a username and the device timezone", async () => {
+ await expect(
+ createBefore({ ...newUser, isAnonymous: true }, contextWith({ "x-client-timezone": "Asia/Kolkata" })),
+ ).resolves.toEqual({
+ data: expect.objectContaining({
+ timezone: "Asia/Kolkata",
+ username: expect.stringMatching(/^guest-/),
+ displayUsername: expect.stringMatching(/^guest-/),
+ }),
+ });
+ });
+});
+
it.each([
["GET", "/reference"],
["GET", "/token"],
diff --git a/packages/auth/src/config.ts b/packages/auth/src/config.ts
index 79823f7c3..1b1bbe2e1 100644
--- a/packages/auth/src/config.ts
+++ b/packages/auth/src/config.ts
@@ -9,7 +9,7 @@ import { oauthProvider } from "@better-auth/oauth-provider";
import { passkey } from "@better-auth/passkey";
import { compare, hash } from "bcryptjs";
import { APIError, betterAuth } from "better-auth";
-import { createAuthMiddleware } from "better-auth/api";
+import { addOAuthServerContext, createAuthMiddleware, getOAuthState } from "better-auth/api";
import { deleteSessionCookie, setSessionCookie } from "better-auth/cookies";
import { admin, anonymous, jwt, openAPI } from "better-auth/plugins";
import { genericOAuth } from "better-auth/plugins/generic-oauth";
@@ -367,11 +367,21 @@ const getAuthConfig = () => {
databaseHooks: {
user: {
create: {
- // Guests sign in without a username. The tail of a UUIDv7 is random; its head is a timestamp.
- before: (user) => {
- if (!user.isAnonymous) return Promise.resolve(undefined);
+ before: async (user, context) => {
+ // New accounts inherit the device timezone from the auth request, so interview times,
+ // reminders and schedules are right from the first use. Social callbacks don't carry the
+ // header; the sign-in hook stores the validated zone in the signed OAuth state.
+ const fromHeader = timezoneSchema.safeParse(context?.headers?.get("x-client-timezone"));
+ // Direct calls outside an auth request have no OAuth state to read.
+ const oauthState = context ? await getOAuthState().catch(() => null) : null;
+ const fromOAuth = timezoneSchema.safeParse(oauthState?.serverContext?.timezone);
+ const timezone = fromHeader.success ? fromHeader.data : fromOAuth.success ? fromOAuth.data : undefined;
+ const data = timezone ? { ...user, timezone } : user;
+ if (!user.isAnonymous) return timezone ? { data } : undefined;
+
+ // Guests sign in without a username. The tail of a UUIDv7 is random; its head is a timestamp.
const username = `guest-${generateId().slice(-12)}`;
- return Promise.resolve({ data: { ...user, username, displayUsername: username } });
+ return { data: { ...data, username, displayUsername: username } };
},
},
delete: {
@@ -392,6 +402,13 @@ const getAuthConfig = () => {
hooks: {
before: createAuthMiddleware(async (ctx) => {
+ if (ctx.path === "/sign-in/social") {
+ const timezone = timezoneSchema.safeParse(ctx.headers?.get("x-client-timezone"));
+ // Keep the device timezone across the provider redirect in server-only state, so the
+ // callback can start a new account there without trusting redirect parameters.
+ if (timezone.success) await addOAuthServerContext({ timezone: timezone.data });
+ }
+
const user = accountUser.getStore();
// Sign-up copies displayUsername into username when username is missing, so either one claims the name.
const requestedUsername: unknown = ctx.body?.username ?? ctx.body?.displayUsername;
diff --git a/packages/auth/src/timezone-signup.test.ts b/packages/auth/src/timezone-signup.test.ts
new file mode 100644
index 000000000..932c9d6b6
--- /dev/null
+++ b/packages/auth/src/timezone-signup.test.ts
@@ -0,0 +1,62 @@
+import { describe, expect, it, vi } from "vite-plus/test";
+import { env } from "@reactive-resume/env/server";
+
+const oauthState = vi.hoisted(() => ({
+ addOAuthServerContext: vi.fn(),
+ getOAuthState: vi.fn<() => Promise<{ serverContext?: { timezone?: unknown } } | null>>(),
+}));
+
+vi.mock("better-auth/api", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("better-auth/api")>()),
+ ...oauthState,
+}));
+
+const { auth } = await import("./config");
+
+const now = new Date();
+const newUser = {
+ id: "new-user",
+ email: "[email protected]",
+ emailVerified: false,
+ name: "New user",
+ createdAt: now,
+ updatedAt: now,
+};
+
+describe("social sign-up timezone", () => {
+ const createBefore = auth.options.databaseHooks?.user?.create?.before;
+
+ if (!createBefore) throw new Error("Missing user create hook");
+
+ it("keeps the device timezone across the provider redirect", async () => {
+ oauthState.getOAuthState.mockResolvedValue(null);
+
+ await auth.handler(
+ new Request(`${env.APP_URL}/api/auth/sign-in/social`, {
+ method: "POST",
+ headers: new Headers({
+ "content-type": "application/json",
+ origin: env.APP_URL,
+ "x-client-timezone": "Europe/Berlin",
+ }),
+ body: JSON.stringify({ provider: "github" }),
+ }),
+ );
+
+ expect(oauthState.addOAuthServerContext).toHaveBeenCalledWith({ timezone: "Europe/Berlin" });
+ });
+
+ it("starts the account from the timezone saved in the OAuth state", async () => {
+ oauthState.getOAuthState.mockResolvedValue({ serverContext: { timezone: "Europe/Berlin" } });
+
+ await expect(createBefore(newUser, { headers: new Headers() } as never)).resolves.toEqual({
+ data: expect.objectContaining({ timezone: "Europe/Berlin" }),
+ });
+ });
+
+ it("ignores an invalid timezone in the OAuth state", async () => {
+ oauthState.getOAuthState.mockResolvedValue({ serverContext: { timezone: "Not/A_Timezone" } });
+
+ await expect(createBefore(newUser, { headers: new Headers() } as never)).resolves.toBeUndefined();
+ });
+});