You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
985 B
37 lines
985 B
import type { H3Event } from "h3";
|
|
import { getCookie, setCookie, deleteCookie } from "h3";
|
|
|
|
export const SESSION_COOKIE_NAME = "pp_session";
|
|
|
|
export function readSessionIdFromCookie(event: H3Event): string | undefined {
|
|
return getCookie(event, SESSION_COOKIE_NAME);
|
|
}
|
|
|
|
export function writeSessionCookie(
|
|
event: H3Event,
|
|
sessionId: string,
|
|
maxAgeSeconds: number,
|
|
): void {
|
|
const secure = process.env.NODE_ENV === "production";
|
|
const domain = process.env.COOKIE_DOMAIN?.trim() || undefined;
|
|
setCookie(event, SESSION_COOKIE_NAME, sessionId, {
|
|
httpOnly: true,
|
|
sameSite: "lax",
|
|
secure,
|
|
path: "/",
|
|
maxAge: maxAgeSeconds,
|
|
domain,
|
|
});
|
|
}
|
|
|
|
export function clearSessionCookie(event: H3Event): void {
|
|
const secure = process.env.NODE_ENV === "production";
|
|
const domain = process.env.COOKIE_DOMAIN?.trim() || undefined;
|
|
deleteCookie(event, SESSION_COOKIE_NAME, {
|
|
path: "/",
|
|
httpOnly: true,
|
|
sameSite: "lax",
|
|
secure,
|
|
domain,
|
|
});
|
|
}
|
|
|