add user accounts and OSM peak catalog with zoom-based notability
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { error, redirect, type Handle } from '@sveltejs/kit';
|
||||
import { validateSession } from '$lib/server/auth';
|
||||
|
||||
const PUBLIC_PATHS = new Set(['/login', '/signup']);
|
||||
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
event.locals.user = validateSession(event.cookies.get('session'));
|
||||
|
||||
const path = event.url.pathname;
|
||||
if (!event.locals.user && !PUBLIC_PATHS.has(path)) {
|
||||
if (path.startsWith('/api/')) error(401, 'Not signed in');
|
||||
redirect(303, '/login');
|
||||
}
|
||||
if (event.locals.user && PUBLIC_PATHS.has(path)) {
|
||||
redirect(303, '/');
|
||||
}
|
||||
|
||||
return resolve(event);
|
||||
};
|
||||
Reference in New Issue
Block a user