Skip to content

Commit 5cefc21

Browse files
stolinskiclaude
andcommitted
Check a session once when an app asks get-session
The hook read the session on every request, and the auth API then checked it again, so every app's session check paid for two. On the API it also took the refresh whose cookie the answer must carry. Only pages read it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 907bb16 commit 5cefc21

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎src/hooks.server.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ export const handle: Handle = async ({ event, resolve }) => {
6060
const auth = create_auth(environment);
6161
event.locals.auth = auth;
6262
event.locals.is_local_development = environment.is_local_development;
63-
const session = await auth.api.getSession({
64-
headers: event.request.headers
65-
});
63+
// The auth API checks a session itself, so reading one here would make every app's get-session do
64+
// it twice, and take the refresh whose cookie that answer must carry. Only pages read these.
65+
const session = is_auth_path
66+
? null
67+
: await auth.api.getSession({
68+
headers: event.request.headers
69+
});
6670

6771
if (session) {
6872
event.locals.session = session.session;

0 commit comments

Comments
 (0)