diff --git a/Mode3Test/frontend/index.html b/Mode3Test/frontend/index.html index 782aaff..1fafeae 100644 --- a/Mode3Test/frontend/index.html +++ b/Mode3Test/frontend/index.html @@ -2329,7 +2329,14 @@ if (!link || fileCache.has(link)) return; // Skip if no link or already cached try { - const graphToken = await ensureGraphToken(); + // Always refresh token before critical file operation to ensure it's fresh + let graphToken = await refreshGraphToken(); + + // If no token after refresh, try to ensure one exists + if (!graphToken) { + graphToken = await ensureGraphToken(); + } + const headers = graphToken ? { 'x-graph-token': graphToken } : {}; const controller = new AbortController(); @@ -2865,7 +2872,14 @@ `; - const graphToken = await ensureGraphToken(); + // Always refresh token before opening folder to ensure it's fresh + let graphToken = await refreshGraphToken(); + + // If no token after refresh, try to ensure one exists + if (!graphToken) { + graphToken = await ensureGraphToken(); + } + const headers = graphToken ? { 'x-graph-token': graphToken } : {}; try { @@ -2907,11 +2921,37 @@ console.error('❌ job-files error for', job.Job_Number, err); const authExpired = err?.message === 'AUTH_EXPIRED' || String(err || '').includes('401'); const timedOut = err?.name === 'AbortError'; - const friendly = authExpired - ? 'Your Microsoft Graph session expired. Click Re-authenticate to sign in again.' - : timedOut - ? 'Request timed out. If this keeps happening, re-authenticate and retry.' - : (err?.message || 'Unknown error'); + + // If auth expired, silently clear and redirect + if (authExpired) { + try { pb?.authStore?.clear?.(); } catch {} + try { localStorage.removeItem(GRAPH_TOKEN_KEY); } catch {} + try { localStorage.removeItem('pocketbase_auth'); } catch {} + try { sessionStorage.clear(); } catch {} + // Show error but with auto-redirect option + iframeLoader.classList.remove('hidden'); + iframeLoader.innerHTML = ` +