Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
⚡️ Refresh session at most once a day (#2503)
Luke Vellaf968aecac1cd
diff --git a/apps/web/src/components/session-refresher.tsx b/apps/web/src/components/session-refresher.tsxindex 57db7efe1..a7678a4df 100644--- a/apps/web/src/components/session-refresher.tsx+++ b/apps/web/src/components/session-refresher.tsx@@ -1,10 +1,16 @@import { getSession } from "@/lib/auth";import { SessionKeepAlive } from "./session-keep-alive";+const ONE_DAY_MS = 24 * 60 * 60 * 1000;+// Keeps an existing session (guest OR authenticated) alive while the user is// active. Gated on getSession — which reads the cookie cache — so truly// anonymous viewers with no session never mount the client keep-alive and// never trigger a /get-session request. Safe to mount on public layouts.+//+// SessionKeepAlive only mounts once the session is at least a day old, matching+// better-auth's `updateAge` of one day: refreshing more often would just fire+// /get-session requests that can't advance the sliding expiry anyway.export async function SessionRefresher() {const session = await getSession();@@ -12,5 +18,11 @@ export async function SessionRefresher() {return null;}+ const age = Date.now() - new Date(session.updatedAt).getTime();++ if (age < ONE_DAY_MS) {+ return null;+ }+return <SessionKeepAlive />;}diff --git a/apps/web/src/lib/auth.ts b/apps/web/src/lib/auth.tsindex 52e758327..7d72c0ff8 100644--- a/apps/web/src/lib/auth.ts+++ b/apps/web/src/lib/auth.ts@@ -509,6 +509,7 @@ export const getSession = cache(async () => {timeZone: session.user.timeZone ?? undefined,},expires: session.session.expiresAt.toISOString(),+ updatedAt: session.session.updatedAt.toISOString(),};}} catch (e) {