Implement basic auth on portal
This commit is contained in:
@@ -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, "/");
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user