fix: cache auth session on locals to prevent cookies.set after response
All checks were successful
CI / update (push) Successful in 2m19s
All checks were successful
CI / update (push) Successful in 2m19s
The authorization hook already calls locals.auth() which can set cookies. Layout server loads calling auth() again caused a race where cookies.set() fired after the response started streaming. Now the hook stashes the session on locals.session and all layouts reuse it.
This commit is contained in:
@@ -2,6 +2,6 @@ import type { LayoutServerLoad } from "./$types"
|
||||
|
||||
export const load : LayoutServerLoad = async ({locals}) => {
|
||||
return {
|
||||
session: await locals.auth()
|
||||
session: locals.session ?? await locals.auth()
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user