feat: working login and logged out

This commit is contained in:
2026-09-10 23:40:08 +02:00
parent 300b1ce774
commit ac56bf4894
7 changed files with 97 additions and 24 deletions
+27
View File
@@ -1,3 +1,4 @@
import { deleteCookie, getCookies, setCookie } from "@std/http/cookie";
import { createDefine } from "fresh";
// This specifies the type of "ctx.state" which is used to share
@@ -7,3 +8,29 @@ export interface State {
}
export const define = createDefine<State>();
export function setAuthCookie(
req: Request,
headers: Headers,
) {
const url = new URL(req.url);
setCookie(headers, {
name: "auth",
value: "ok",
maxAge: 60 * 60,
sameSite: "Lax",
domain: url.hostname,
path: "/",
secure: true,
});
}
export function unsetAuthCookie(headers: Headers) {
deleteCookie(headers, "auth");
}
export function isLoggedIn(req: Request): boolean {
const cookies = getCookies(req.headers);
const authCookie = cookies["auth"];
return authCookie === "ok";
}