Implement basic auth on portal

This commit is contained in:
Dominic Ferrando
2026-06-30 00:24:48 -04:00
parent 9778c05bf0
commit 235c072421
12 changed files with 101 additions and 27 deletions
+15
View File
@@ -0,0 +1,15 @@
import { env } from '$env/dynamic/private';
import { redirect, type Handle } from '@sveltejs/kit';
import { createHmac } from 'node:crypto';
export const handle: Handle = async ({ event, resolve }) => {
const cookieHash = event.cookies.get("session");
const computedHash = createHmac("sha256", env.PORTAL_SECRET)
.update("authenticated")
.digest("hex");
if (event.url.pathname !== "/login" && cookieHash !== computedHash)
redirect(307, "/login");
const response = await resolve(event);
return response;
};