move API protection check into hooks, adjusting corresponding tests
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user