logmein
Viewing readonly version: 123View latest version
Script
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { Cookie, deleteCookie, getCookies, setCookie } from "https://deno.land/std/http/cookie.ts";
function setSessionCookie(key: string): Cookie {
return {
name: "session",
value: key,
path: "/",
httpOnly: true,
secure: true,
sameSite: "Strict",
};
}
function parseSessionCookie(req: Request): string | null {
const cookies = getCookies(req.headers);
const sessionCookie = cookies["session"];
if (!sessionCookie) return null;
return sessionCookie;
}
export function loginSession(key: string, response: Response): Cookie {
const cookie = setSessionCookie(key);
response.headers.append("Set-Cookie", Cookie.stringify(cookie));
return cookie;
}