28 lines
565 B
TypeScript
28 lines
565 B
TypeScript
import { deleteCookie, getCookies, setCookie } from "@std/http/cookie";
|
|
|
|
export function setAuthCookie(
|
|
headers: Headers,
|
|
) {
|
|
setCookie(headers, {
|
|
name: "auth",
|
|
value: "ok",
|
|
maxAge: 60 * 60,
|
|
sameSite: "Lax",
|
|
path: "/",
|
|
secure: true,
|
|
httpOnly: true,
|
|
});
|
|
}
|
|
|
|
export function unsetAuthCookie(headers: Headers) {
|
|
deleteCookie(headers, "auth", {
|
|
path: "/",
|
|
});
|
|
}
|
|
|
|
export function isLoggedIn(req: Request): boolean {
|
|
const cookies = getCookies(req.headers);
|
|
const authCookie = cookies["auth"];
|
|
return authCookie === "ok";
|
|
}
|