feat(gateway): 接入统一认证中心本地登录

This commit is contained in:
2026-07-12 20:45:35 +08:00
parent f8d766b916
commit 03abc0eab7
10 changed files with 123 additions and 15 deletions
+13 -5
View File
@@ -1,21 +1,29 @@
const AUTH_TOKEN_STORAGE_KEY = 'easyai_ai_gateway_access_token';
const OIDC_SESSION_TOKEN_STORAGE_KEY = 'easyai_ai_gateway_oidc_access_token';
export function readStoredAccessToken() {
if (typeof window === 'undefined') return '';
try {
return window.localStorage.getItem(AUTH_TOKEN_STORAGE_KEY) ?? '';
return window.sessionStorage.getItem(OIDC_SESSION_TOKEN_STORAGE_KEY)
?? window.localStorage.getItem(AUTH_TOKEN_STORAGE_KEY)
?? '';
} catch {
return '';
}
}
export function persistAccessToken(value: string) {
export function persistAccessToken(value: string, storage: 'local' | 'session' = 'local') {
if (typeof window === 'undefined') return;
try {
if (value) {
window.localStorage.setItem(AUTH_TOKEN_STORAGE_KEY, value);
} else {
if (!value) {
window.localStorage.removeItem(AUTH_TOKEN_STORAGE_KEY);
window.sessionStorage.removeItem(OIDC_SESSION_TOKEN_STORAGE_KEY);
} else if (storage === 'session') {
window.localStorage.removeItem(AUTH_TOKEN_STORAGE_KEY);
window.sessionStorage.setItem(OIDC_SESSION_TOKEN_STORAGE_KEY, value);
} else {
window.sessionStorage.removeItem(OIDC_SESSION_TOKEN_STORAGE_KEY);
window.localStorage.setItem(AUTH_TOKEN_STORAGE_KEY, value);
}
} catch {
// Ignore storage failures so private browsing or quota issues do not break login.