24 lines
680 B
TypeScript
24 lines
680 B
TypeScript
import type { FastifyReply } from "fastify";
|
|
|
|
export const ADMIN_SESSION_COOKIE = "admin_session";
|
|
const ADMIN_SESSION_MAX_AGE_SECONDS = 60 * 60 * 24 * 7;
|
|
|
|
export function setAdminSessionCookie(reply: FastifyReply, token: string): void {
|
|
reply.setCookie(ADMIN_SESSION_COOKIE, token, {
|
|
path: "/",
|
|
httpOnly: true,
|
|
sameSite: "strict",
|
|
secure: process.env.NODE_ENV === "production",
|
|
maxAge: ADMIN_SESSION_MAX_AGE_SECONDS,
|
|
});
|
|
}
|
|
|
|
export function clearAdminSessionCookie(reply: FastifyReply): void {
|
|
reply.clearCookie(ADMIN_SESSION_COOKIE, {
|
|
path: "/",
|
|
httpOnly: true,
|
|
sameSite: "strict",
|
|
secure: process.env.NODE_ENV === "production",
|
|
});
|
|
}
|