import { redirect } from '@sveltejs/kit'; import type { Handle } from '@sveltejs/kit'; import { renewSession } from '$lib/server/auth'; const PUBLIC_ASSETS = new Set([ '/favicon.png', '/manifest.webmanifest', '/pwa-192x192.png', '/pwa-512x512.png', '/registerSW.js', '/sw.js', ]); function isPublicPath(pathname: string): boolean { return ( pathname === '/login' || pathname.startsWith('/_app/') || PUBLIC_ASSETS.has(pathname) ); } export const handle: Handle = async ({ event, resolve }) => { if (isPublicPath(event.url.pathname)) return resolve(event); const secure = event.url.protocol === 'https:'; if (renewSession(event.cookies, secure)) return resolve(event); const next = `${event.url.pathname}${event.url.search}`; throw redirect(303, `/login?next=${encodeURIComponent(next)}`); };