bergere-enchantee / src /hooks.server.ts
coyotte508's picture
coyotte508 HF staff
✨ Upload new photos & products, delete existing products
8a49743
raw
history blame
566 Bytes
import { collections } from '$lib/server/db';
import type { Handle } from '@sveltejs/kit';
export const handle: Handle = async ({ event, resolve }) => {
const token = event.cookies.get('bergereToken');
if (token) {
event.locals.user = await collections.users.findOne({ token });
}
if (event.url.pathname.startsWith('/admin') && event.locals.user?.authority !== 'admin') {
return new Response('', {
status: 303,
headers: { location: `${event.url.protocol}//${event.url.host}` }
});
}
const response = await resolve(event);
return response;
};