From 24862ca1de01f885a28a736705d7e058a43a46bd Mon Sep 17 00:00:00 2001 From: Oliver Kieselbach Date: Fri, 27 Feb 2026 15:29:24 +0100 Subject: [PATCH] fix: allow retry when fetchSessionDetails fails due to token not ready When galacticAdminMode is true, the initial data fetch effect fires immediately (before MSAL settles). If getAccessToken() returns null, hasInitialFetch was left as true, permanently blocking any retry. The session page would load empty and never recover. Fix: reset hasInitialFetch on token/network failures so the effect can retry. Added `user` to dependencies so the effect re-fires once MSAL settles and user info is available. Co-Authored-By: Claude Opus 4.6 --- .../app/sessions/[sessionId]/page.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Web/autopilot-monitor-web/app/sessions/[sessionId]/page.tsx b/src/Web/autopilot-monitor-web/app/sessions/[sessionId]/page.tsx index 3a3835c6..a6669e03 100644 --- a/src/Web/autopilot-monitor-web/app/sessions/[sessionId]/page.tsx +++ b/src/Web/autopilot-monitor-web/app/sessions/[sessionId]/page.tsx @@ -159,8 +159,9 @@ export default function SessionDetailPage() { const { getAccessToken, user } = useAuth(); const { addNotification } = useNotifications(); - // Initial data fetch — wait for a real tenantId before calling the backend. + // Initial data fetch — wait for auth to be ready and a real tenantId before calling the backend. // TenantContext initializes to '' and updates once AuthContext finishes loading. + // `user` is included so that a retry fires once MSAL settles (token becomes available). useEffect(() => { if (!sessionId) return; if (!galacticAdminMode && !tenantId) return; // wait for real tenant ID @@ -181,7 +182,7 @@ export default function SessionDetailPage() { fetchSessionDetails(); // fetchEvents will be called after sessionTenantId is set - }, [sessionId, tenantId, galacticAdminMode]); + }, [sessionId, tenantId, galacticAdminMode, user]); // Fetch events and analysis when we have the session's tenant ID useEffect(() => { @@ -299,12 +300,13 @@ export default function SessionDetailPage() { ? `${API_BASE_URL}/api/galactic/sessions` : `${API_BASE_URL}/api/sessions?tenantId=${tenantId}`; - // Get access token and include Authorization header const token = await getAccessToken(); if (!token) { addNotification('error', 'Authentication Error', 'Failed to get access token. Please try logging in again.', 'session-detail-auth-error'); + // Allow retry — token may not be ready yet (MSAL still initializing) + hasInitialFetch.current = false; return; } const response = await fetch(endpoint, { @@ -326,6 +328,8 @@ export default function SessionDetailPage() { } catch (error) { console.error("Failed to fetch session details:", error); addNotification('error', 'Backend Not Reachable', 'Unable to load session details. Please check your connection.', 'session-detail-fetch-error'); + // Allow retry on network errors + hasInitialFetch.current = false; } };