refactor: remove localStorage persistence from tokenStore to enforce in-memory session management
This commit is contained in:
@@ -2,38 +2,14 @@ export type StoredTokens = {
|
||||
access_token: string;
|
||||
};
|
||||
|
||||
const LS_KEY = "uhm_auth_tokens_v1";
|
||||
|
||||
let cached: StoredTokens | null = null;
|
||||
|
||||
function safeParseTokens(raw: string | null): StoredTokens | null {
|
||||
if (!raw) return null;
|
||||
try {
|
||||
const v = JSON.parse(raw) as Partial<StoredTokens>;
|
||||
if (!v || typeof v !== "object") return null;
|
||||
if (typeof v.access_token !== "string") return null;
|
||||
if (!v.access_token.trim()) return null;
|
||||
return { access_token: v.access_token };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function getStoredTokens(): StoredTokens | null {
|
||||
if (cached) return cached;
|
||||
if (typeof window === "undefined") return null;
|
||||
cached = safeParseTokens(window.localStorage.getItem(LS_KEY));
|
||||
return cached;
|
||||
}
|
||||
|
||||
export function setStoredTokens(tokens: StoredTokens | null): void {
|
||||
cached = tokens;
|
||||
if (typeof window === "undefined") return;
|
||||
if (!tokens) {
|
||||
window.localStorage.removeItem(LS_KEY);
|
||||
return;
|
||||
}
|
||||
window.localStorage.setItem(LS_KEY, JSON.stringify(tokens));
|
||||
}
|
||||
|
||||
export function getAccessToken(): string | null {
|
||||
|
||||
Reference in New Issue
Block a user