43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
import { redirect } from '@sveltejs/kit';
|
|
import type { Handle } from '@sveltejs/kit/hooks';
|
|
import { deleteSession, getSessionUser, hasUsers, SESSION_COOKIE } from '#lib/server/auth.js';
|
|
|
|
const publicPaths = new Set([
|
|
'/',
|
|
'/healthz',
|
|
'/login',
|
|
'/setup',
|
|
'/einladung',
|
|
'/passwort-vergessen',
|
|
'/passwort-zuruecksetzen'
|
|
]);
|
|
|
|
export const handle: Handle = async ({ event, resolve }) => {
|
|
const presentationPath = event.url.pathname.startsWith('/heinzlive/');
|
|
const presentationTestPath = /^\/fundus\/[^/]+\/praesentation(?:\/|$)/.test(event.url.pathname);
|
|
const token = event.cookies.get(SESSION_COOKIE);
|
|
event.locals.user = getSessionUser(token);
|
|
if (token && !event.locals.user) deleteSession(event.cookies);
|
|
|
|
if (!presentationPath && !publicPaths.has(event.url.pathname) && !event.locals.user) {
|
|
redirect(303, hasUsers() ? '/login' : '/setup');
|
|
}
|
|
|
|
const response = await resolve(event);
|
|
response.headers.set('Referrer-Policy', 'same-origin');
|
|
response.headers.set('X-Content-Type-Options', 'nosniff');
|
|
response.headers.set('X-Frame-Options', 'DENY');
|
|
if (presentationPath || presentationTestPath) {
|
|
response.headers.set('Cache-Control', 'no-store');
|
|
response.headers.set('Referrer-Policy', 'strict-origin-when-cross-origin');
|
|
response.headers.set(
|
|
'Content-Security-Policy',
|
|
"frame-src https://www.youtube-nocookie.com https://www.youtube.com https://www.tiktok.com; frame-ancestors 'none'"
|
|
);
|
|
}
|
|
if (event.url.pathname === '/einladung' || event.url.pathname === '/passwort-zuruecksetzen') {
|
|
response.headers.set('Cache-Control', 'no-store');
|
|
}
|
|
return response;
|
|
};
|