import { decryptToken } from '$lib/auth';

/** @type {import('@sveltejs/kit').Handle} */
export async function handle({ event, resolve }) {
	const jwt = event.cookies.get('session');
	try {
		if (jwt) {
			event.locals.user = decryptToken(jwt);
			return resolve(event);
		}
	} catch (err) {
		await event.cookies.delete('session');
		event.locals.user = null;
	}
	return resolve(event);
}
