aboutsummaryrefslogtreecommitdiff
path: root/src/hooks.server.ts
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-08-13 09:38:16 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-08-13 09:38:16 +0200
commit007384be67559e1848ee0a8a1726c6b0fa39a221 (patch)
tree6b11cc43bd00967564c5bc74aed60168331f225b /src/hooks.server.ts
parentb30150a8feb960c0667eaff6cb105dcc55b65744 (diff)
feat(auth): add persistent family login
Diffstat (limited to 'src/hooks.server.ts')
-rw-r--r--src/hooks.server.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/hooks.server.ts b/src/hooks.server.ts
new file mode 100644
index 0000000..f1f5b52
--- /dev/null
+++ b/src/hooks.server.ts
@@ -0,0 +1,30 @@
+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)}`);
+};