-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
40 lines (33 loc) · 1.09 KB
/
Copy pathauth.ts
File metadata and controls
40 lines (33 loc) · 1.09 KB
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
37
38
39
40
import type { CompanyProfile } from "@/lib/types";
const TOKEN_KEY = "monitor.jwt";
const COMPANY_KEY = "monitor.company";
export function getToken() {
if (typeof window === "undefined") return null;
return window.localStorage.getItem(TOKEN_KEY);
}
export function setToken(token: string) {
if (typeof window === "undefined") return;
window.localStorage.setItem(TOKEN_KEY, token);
}
export function clearToken() {
if (typeof window === "undefined") return;
window.localStorage.removeItem(TOKEN_KEY);
}
export function getCompanyProfile(): CompanyProfile | null {
if (typeof window === "undefined") return null;
const raw = window.localStorage.getItem(COMPANY_KEY);
if (!raw) return null;
try {
return JSON.parse(raw) as CompanyProfile;
} catch {
return null;
}
}
export function setCompanyProfile(profile: CompanyProfile) {
if (typeof window === "undefined") return;
window.localStorage.setItem(COMPANY_KEY, JSON.stringify(profile));
}
export function clearCompanyProfile() {
if (typeof window === "undefined") return;
window.localStorage.removeItem(COMPANY_KEY);
}