mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-28 00:50:57 +00:00
feat: migrate authentication storage to use js-cookie for improved token management
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export const SESSION_HEADER_KEYS = {
|
||||
tenantId: 'x-tenant-id',
|
||||
organizationUnitId: 'x-organization-unit-id',
|
||||
@@ -11,17 +13,10 @@ 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);
|
||||
const cookie = Cookies.get(key);
|
||||
if (cookie) return cookie;
|
||||
const stored = localStorage.getItem(key);
|
||||
if (stored) return stored;
|
||||
|
||||
Reference in New Issue
Block a user