This commit is contained in:
13
src/hooks.server.ts
Normal file
13
src/hooks.server.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { building } from '$app/environment';
|
||||
import { auth } from '$lib/server/auth';
|
||||
import type { Handle } from '@sveltejs/kit';
|
||||
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
// Match the endpoint path here: the dev proxy may terminate HTTPS before Vite.
|
||||
// Better Auth validates request origins against its configured public URL.
|
||||
if (!building && event.url.pathname.startsWith('/api/auth/')) return auth.handler(event.request);
|
||||
const session = building ? null : await auth.api.getSession({ headers: event.request.headers });
|
||||
event.locals.user = session?.user ?? null;
|
||||
event.locals.session = session?.session ?? null;
|
||||
return resolve(event);
|
||||
};
|
||||
Reference in New Issue
Block a user