create landing page for boursemes
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import {
|
||||
getTokenName,
|
||||
LEGACY_TOKEN_SUFFIX,
|
||||
SESSION_AUTH_KEY,
|
||||
} from '@/themeConfig'
|
||||
|
||||
function legacyTokenKeys(): string[] {
|
||||
const keys: string[] = []
|
||||
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i)
|
||||
if (key?.endsWith(LEGACY_TOKEN_SUFFIX)) {
|
||||
keys.push(key)
|
||||
}
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
||||
|
||||
/** خواندن توکن — اول session ثابت، بعد کلید tenant، بعد هر *_app_token */
|
||||
export function findStoredAuthToken(): string | null {
|
||||
const session = localStorage.getItem(SESSION_AUTH_KEY)
|
||||
if (session) {
|
||||
return session
|
||||
}
|
||||
|
||||
const named = localStorage.getItem(getTokenName())
|
||||
if (named) {
|
||||
localStorage.setItem(SESSION_AUTH_KEY, named)
|
||||
return named
|
||||
}
|
||||
|
||||
for (const key of legacyTokenKeys()) {
|
||||
const value = localStorage.getItem(key)
|
||||
if (value) {
|
||||
localStorage.setItem(SESSION_AUTH_KEY, value)
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function persistAuthToken(token: string | undefined | null) {
|
||||
if (!token) {
|
||||
return
|
||||
}
|
||||
|
||||
localStorage.setItem(SESSION_AUTH_KEY, token)
|
||||
localStorage.setItem(getTokenName(), token)
|
||||
}
|
||||
|
||||
export function clearStoredAuthTokens() {
|
||||
localStorage.removeItem(SESSION_AUTH_KEY)
|
||||
|
||||
for (const key of legacyTokenKeys()) {
|
||||
localStorage.removeItem(key)
|
||||
}
|
||||
}
|
||||
|
||||
export function collectAuthTokensForPreserve(): Record<string, string> {
|
||||
const preserved: Record<string, string> = {}
|
||||
|
||||
for (const key of [SESSION_AUTH_KEY, getTokenName(), ...legacyTokenKeys()]) {
|
||||
const value = localStorage.getItem(key)
|
||||
if (value) {
|
||||
preserved[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
return preserved
|
||||
}
|
||||
Reference in New Issue
Block a user