mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
18 lines
570 B
TypeScript
18 lines
570 B
TypeScript
|
|
import { redirect, type Handle } from '@sveltejs/kit';
|
||
|
|
import { auth } from '$lib/server/lucia';
|
||
|
|
|
||
|
|
export const handle: Handle = async ({ event, resolve }) => {
|
||
|
|
event.locals.auth = auth.handleRequest(event);
|
||
|
|
console.log(JSON.stringify(event));
|
||
|
|
if (event.locals?.auth) {
|
||
|
|
const { user } = await event.locals.auth.validateUser();
|
||
|
|
event.locals.user = user;
|
||
|
|
if (event.route.id?.startsWith('/(protected)')) {
|
||
|
|
if (!user) throw redirect(302, '/auth/sign-in');
|
||
|
|
if (!user.verified) throw redirect(302, '/auth/verify/email');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return await resolve(event);
|
||
|
|
};
|