move API protection check into hooks, adjusting corresponding tests

This commit is contained in:
2025-11-04 09:22:53 +01:00
parent 3c16bc89e5
commit fd907c9851
10 changed files with 47 additions and 74 deletions

View File

@@ -14,5 +14,15 @@ export const handle: Handle = async ({ event, resolve }) => {
event.cookies.delete('session', {path: ROUTE_NAMES.ROOT});
event.locals.user = null;
}
if (event.url.pathname.startsWith('/api')) {
if (!event.locals.user) {
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
status: 401,
headers: { 'Content-Type': 'application/json' }
});
}
}
return await resolve(event);
}