File size: 1,075 Bytes
62cade8 | 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 26 27 28 29 30 31 32 33 34 35 36 | const STORAGE_KEY = "checkout_admin_token";
const ROLE_KEY = "checkout_admin_role";
export function getAdminToken(): string | null {
if (typeof window === "undefined") return null;
return localStorage.getItem(STORAGE_KEY);
}
export function getAdminRole(): string | null {
if (typeof window === "undefined") return null;
return localStorage.getItem(ROLE_KEY);
}
export function setAdminSession(token: string, role: string): void {
localStorage.setItem(STORAGE_KEY, token);
localStorage.setItem(ROLE_KEY, role);
}
/** @deprecated Prefer setAdminSession — defaults role to staff */
export function setAdminToken(token: string): void {
setAdminSession(token, "staff");
}
export function clearAdminToken(): void {
localStorage.removeItem(STORAGE_KEY);
localStorage.removeItem(ROLE_KEY);
}
export function adminFetchHeaders(json = false): HeadersInit {
const headers: Record<string, string> = {};
if (json) headers["Content-Type"] = "application/json";
const t = getAdminToken();
if (t) headers.Authorization = `Bearer ${t}`;
return headers;
}
|