UNPKG

@lucia-auth/sveltekit

Version:
30 lines (29 loc) 852 B
import { generateChecksum } from "./crypto.js"; export const handleServerSession = (fn) => { const handleServerSessionCore = async ({ locals }) => { const { session, user } = await locals.validateUser(); if (session) { return { _lucia: { user, sessionChecksum: generateChecksum(session.sessionId) } }; } return { _lucia: { user: null, sessionChecksum: null } }; }; return async (event) => { const { _lucia } = await handleServerSessionCore(event); const loadFunction = fn ?? (async () => { }); const result = (await loadFunction(event)) || {}; return { _lucia, ...result }; }; };