File size: 566 Bytes
de10f77
bd9595b
 
 
 
 
 
de10f77
bd9595b
 
8a49743
 
 
 
 
 
 
bd9595b
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;
};