aboutsummaryrefslogtreecommitdiff
path: root/src/routes/login/+page.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/routes/login/+page.server.ts
parentb30150a8feb960c0667eaff6cb105dcc55b65744 (diff)
feat(auth): add persistent family login
Diffstat (limited to 'src/routes/login/+page.server.ts')
-rw-r--r--src/routes/login/+page.server.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/routes/login/+page.server.ts b/src/routes/login/+page.server.ts
new file mode 100644
index 0000000..88c5f2d
--- /dev/null
+++ b/src/routes/login/+page.server.ts
@@ -0,0 +1,30 @@
+import { fail, redirect } from '@sveltejs/kit';
+import { setSession, verifyPassword } from '$lib/server/auth';
+import type { Actions, PageServerLoad } from './$types';
+
+function safeNext(value: string | null): string {
+ return value?.startsWith('/') && !value.startsWith('//') ? value : '/';
+}
+
+export const load: PageServerLoad = ({ url }) => ({
+ next: safeNext(url.searchParams.get('next')),
+});
+
+export const actions: Actions = {
+ default: async ({ request, cookies, url }) => {
+ const data = await request.formData();
+ const password = data.get('password')?.toString() ?? '';
+ const next = safeNext(
+ data.get('next')?.toString() ?? url.searchParams.get('next'),
+ );
+
+ if (!verifyPassword(password)) {
+ console.warn('[auth] failed login attempt');
+ return fail(401, { error: 'Mot de passe incorrect', next });
+ }
+
+ console.info('[auth] login succeeded');
+ setSession(cookies, url.protocol === 'https:');
+ throw redirect(303, next);
+ },
+};