feat: implement local authentication mode and update related components
This commit is contained in:
43
frontend/src/auth/localAuth.ts
Normal file
43
frontend/src/auth/localAuth.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
"use client";
|
||||
|
||||
let localToken: string | null = null;
|
||||
const STORAGE_KEY = "mc_local_auth_token";
|
||||
|
||||
export function isLocalAuthMode(): boolean {
|
||||
return process.env.NEXT_PUBLIC_AUTH_MODE === "local";
|
||||
}
|
||||
|
||||
export function setLocalAuthToken(token: string): void {
|
||||
localToken = token;
|
||||
if (typeof window === "undefined") return;
|
||||
try {
|
||||
window.sessionStorage.setItem(STORAGE_KEY, token);
|
||||
} catch {
|
||||
// Ignore storage failures (private mode / policy).
|
||||
}
|
||||
}
|
||||
|
||||
export function getLocalAuthToken(): string | null {
|
||||
if (localToken) return localToken;
|
||||
if (typeof window === "undefined") return null;
|
||||
try {
|
||||
const stored = window.sessionStorage.getItem(STORAGE_KEY);
|
||||
if (stored) {
|
||||
localToken = stored;
|
||||
return stored;
|
||||
}
|
||||
} catch {
|
||||
// Ignore storage failures (private mode / policy).
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function clearLocalAuthToken(): void {
|
||||
localToken = null;
|
||||
if (typeof window === "undefined") return;
|
||||
try {
|
||||
window.sessionStorage.removeItem(STORAGE_KEY);
|
||||
} catch {
|
||||
// Ignore storage failures (private mode / policy).
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user