mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
feat: update authentication storage to use cookies and improve token retrieval
This commit is contained in:
@@ -11,13 +11,22 @@ const TOKEN_STORAGE_KEYS = [
|
||||
'auth-token',
|
||||
] as const;
|
||||
|
||||
function getCookie(name: string): string | undefined {
|
||||
const match = document.cookie.match(
|
||||
new RegExp('(?:^|;\\s*)' + name + '=([^;]*)'),
|
||||
);
|
||||
return match ? decodeURIComponent(match[1]) : undefined;
|
||||
}
|
||||
|
||||
export function resolveTokenFromStorage(): string | undefined {
|
||||
// cookie first (backoffice stores tokens there), then localStorage (portal / legacy)
|
||||
for (const key of TOKEN_STORAGE_KEYS) {
|
||||
const cookie = getCookie(key);
|
||||
if (cookie) return cookie;
|
||||
const stored = localStorage.getItem(key);
|
||||
if (stored) return stored;
|
||||
}
|
||||
const match = document.cookie.match(/(?:^|;\s*)auth-token=([^;]*)/);
|
||||
return match ? decodeURIComponent(match[1]) : undefined;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function resolveSessionContext(state?: { auth?: { token?: string } }): {
|
||||
|
||||
Reference in New Issue
Block a user