18 lines
650 B
TypeScript
18 lines
650 B
TypeScript
|
|
const SESSION_COOKIE = 'nxtgauge_admin_session';
|
||
|
|
const SESSION_TTL_SECONDS = 60 * 60 * 12;
|
||
|
|
|
||
|
|
export function hasAdminSession(): boolean {
|
||
|
|
if (typeof document === 'undefined') return false;
|
||
|
|
return document.cookie.split(';').some((entry) => entry.trim().startsWith(`${SESSION_COOKIE}=`));
|
||
|
|
}
|
||
|
|
|
||
|
|
export function setAdminSession(): void {
|
||
|
|
if (typeof document === 'undefined') return;
|
||
|
|
document.cookie = `${SESSION_COOKIE}=1; Path=/; Max-Age=${SESSION_TTL_SECONDS}; SameSite=Lax`;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function clearAdminSession(): void {
|
||
|
|
if (typeof document === 'undefined') return;
|
||
|
|
document.cookie = `${SESSION_COOKIE}=; Path=/; Max-Age=0; SameSite=Lax`;
|
||
|
|
}
|