Первая постановка на уведомления
This commit is contained in:
@@ -2,13 +2,25 @@ export type AuthStatus = 'authenticated' | 'guest' | null;
|
||||
|
||||
const KEY = 'han_auth_status';
|
||||
|
||||
function safeGet(key: string): string | null {
|
||||
try { return localStorage.getItem(key); } catch { return null; }
|
||||
}
|
||||
|
||||
function safeSet(key: string, value: string) {
|
||||
try { localStorage.setItem(key, value); } catch { /* ignore */ }
|
||||
}
|
||||
|
||||
function safeRemove(key: string) {
|
||||
try { localStorage.removeItem(key); } catch { /* ignore */ }
|
||||
}
|
||||
|
||||
export function getAuthStatus(): AuthStatus {
|
||||
return (localStorage.getItem(KEY) as AuthStatus) ?? null;
|
||||
return (safeGet(KEY) as AuthStatus) ?? null;
|
||||
}
|
||||
|
||||
export function setAuthStatus(status: AuthStatus) {
|
||||
if (status === null) localStorage.removeItem(KEY);
|
||||
else localStorage.setItem(KEY, status);
|
||||
if (status === null) safeRemove(KEY);
|
||||
else safeSet(KEY, status);
|
||||
}
|
||||
|
||||
export function isGuest() {
|
||||
|
||||
Reference in New Issue
Block a user