Files
platform/apps/portal/src/routes/login/+page.server.ts
T

22 lines
704 B
TypeScript

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, "/");
},
};