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 <noreply@anthropic.com>
This commit is contained in:
Oliver Kieselbach
2026-02-27 15:29:24 +01:00
parent a5e83f066b
commit 24862ca1de
@@ -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;
}
};