From 7a9c500e853a17a9ce3392eb172f9c4ef43f3790 Mon Sep 17 00:00:00 2001 From: iFixKart Dev Date: Fri, 6 Nov 2026 14:31:13 +0530 Subject: [PATCH] fix(migration): ensure auth token is retrieved from storage and cookies for requests and SSE --- app/(admin)/migration/page.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/(admin)/migration/page.tsx b/app/(admin)/migration/page.tsx index ee0a99a..e08b98b 100644 --- a/app/(admin)/migration/page.tsx +++ b/app/(admin)/migration/page.tsx @@ -40,8 +40,24 @@ const getApiBase = (): string => { return `${backendUrl}/api/v1/migration`; }; +const getAuthToken = (): string | null => { + let token = getAccessToken(); + if (!token && typeof window !== 'undefined') { + token = + localStorage.getItem('access_token') || + localStorage.getItem('token') || + sessionStorage.getItem('access_token') || + sessionStorage.getItem('token'); + if (!token && document.cookie) { + const match = document.cookie.match(/(?:^|;\s*)(?:access_token|token|jwt)=([^;]+)/); + if (match) token = decodeURIComponent(match[1]); + } + } + return token; +}; + const authFetch = async (url: string, init?: RequestInit): Promise => { - const token = getAccessToken(); + const token = getAuthToken(); const headers = new Headers(init?.headers || {}); if (token) { headers.set('Authorization', `Bearer ${token}`); @@ -288,7 +304,7 @@ export default function MigrationPage() { // Connect SSE Live Stream if (activeId) { - const token = getAccessToken(); + const token = getAuthToken(); const sseUrl = `${apiBase}/jobs/${activeId}/stream${token ? `?token=${encodeURIComponent(token)}` : ''}`; const eventSource = new EventSource(sseUrl); eventSource.onmessage = (event) => {