feat: working login and logged out
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user