feat: migrate authentication storage to use js-cookie for improved token management

This commit is contained in:
estifanos
2026-07-22 09:51:00 +00:00
parent e862d5cd8e
commit a76549b018
5 changed files with 25 additions and 38 deletions

View File

@@ -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;