Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/web/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export const getCurrentUser = cache(async function getCurrentUser(): Promise<Doc
{},
);
}
} catch {
// Auth query/mutation failed - user will remain null
} catch (error) {
console.error("[auth] getCurrentUser failed:", error);
}

return user;
Expand Down
6 changes: 6 additions & 0 deletions apps/web/lib/better-auth/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ export const betterAuthClient = createAuthClient({
credentials: "include",
},
plugins: [convexClient()],
sessionOptions: {
// Disable automatic refetch on tab focus — on mobile, switching apps or
// pulling down the notification shade triggers visibilitychange, causing
// unnecessary /get-session round-trips that temporarily clear auth state.
refetchOnWindowFocus: false,
},
});
4 changes: 2 additions & 2 deletions apps/web/lib/server-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export async function getServerAuth(): Promise<ServerAuthResult> {
},
};
}
} catch {
// Query/mutation failed, fall through to unauthenticated response.
} catch (error) {
console.error("[server-auth] getServerAuth failed:", error);
}

return {
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export const createAuth = (ctx: GenericCtx<DataModel>) => {
emailAndPassword: {
enabled: true,
},
session: {
cookieCache: {
enabled: true,
maxAge: 5 * 60, // 5 minutes — avoids DB lookup on every /get-session
},
},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID!,
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ authComponent.registerRoutes(http, createAuth, {
"http://localhost:3000",
"http://localhost:3001",
process.env.SITE_URL || "",
// Also allow www variant (matches trustedOrigins in auth.ts)
...(process.env.SITE_URL
? [process.env.SITE_URL.replace("://", "://www.")]
: []),
].filter(Boolean),
},
});
Expand Down