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
@@ -0,0 +1,21 @@
import { fail, redirect } from "@sveltejs/kit";
import type { Actions } from "./$types";
import { env } from "$env/dynamic/private";
import { createHmac } from "node:crypto";
export const actions: Actions = {
default: async ({ request, cookies }) => {
const data = await request.formData();
const password = data.get("password");
if (password !== env.PORTAL_PASSWORD)
return fail(401, { error: "Invalid password" });
const hash = createHmac("sha256", env.PORTAL_SECRET)
.update("authenticated")
.digest("hex");
cookies.set("session", hash, { path: "/", maxAge: 60 * 60 * 24 * 7 });
redirect(303, "/");
},
};