29 lines
1 KiB
TypeScript
29 lines
1 KiB
TypeScript
const SESSION_COOKIE = 'nxtgauge_admin_session';
|
|
const SESSION_VALUE = 'internal_management';
|
|
const SESSION_TTL_SECONDS = 60 * 60 * 12;
|
|
|
|
export function hasAdminSession(): boolean {
|
|
if (typeof document === 'undefined') return false;
|
|
// Check cookie exists
|
|
const hasCookie = document.cookie.split(';').some((entry) => entry.trim() === `${SESSION_COOKIE}=${SESSION_VALUE}`);
|
|
// Also check if sessionStorage has a valid token as fallback
|
|
const hasToken = (() => {
|
|
try {
|
|
const token = sessionStorage.getItem('nxtgauge_admin_access_token');
|
|
return Boolean(token && token.trim().length > 0);
|
|
} catch {
|
|
return false;
|
|
}
|
|
})();
|
|
return hasCookie || hasToken;
|
|
}
|
|
|
|
export function setAdminSession(): void {
|
|
if (typeof document === 'undefined') return;
|
|
document.cookie = `${SESSION_COOKIE}=${SESSION_VALUE}; 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`;
|
|
}
|