From 18b55c3f494adb01f7424189ef70795bc7655275 Mon Sep 17 00:00:00 2001 From: SocioWire Date: Sun, 4 Jan 2026 07:55:24 +0000 Subject: [PATCH] Fix OAuth callback crash causing black page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Wrap whoami/refreshProfile calls in try/catch - Add .catch() handlers for async auth operations in useEffect - Prevents React crash when API calls fail during SSO 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/auth/AuthContext.jsx | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/auth/AuthContext.jsx b/src/auth/AuthContext.jsx index ed7accf..b8a4133 100644 --- a/src/auth/AuthContext.jsx +++ b/src/auth/AuthContext.jsx @@ -534,16 +534,22 @@ export function AuthProvider({ children }) { setAuthFromTokens(t); scheduleAutoRefresh(); - const w = await whoami(t.access_token); - if (!w.ok || !w.authenticated) { - setAnon("SSO login desynced. Please login again."); - cleanupAuthUrl(); - return { ok: false, reason: "whoami_failed" }; - } + try { + const w = await whoami(t.access_token); + if (!w.ok || !w.authenticated) { + setAnon("SSO login desynced. Please login again."); + cleanupAuthUrl(); + return { ok: false, reason: "whoami_failed" }; + } - setUser(w.username ? { username: w.username } : null); - setStatus("auth"); - await refreshProfile(t.access_token); + setUser(w.username ? { username: w.username } : null); + setStatus("auth"); + await refreshProfile(t.access_token); + } catch (err) { + console.error("[Auth] Post-SSO verification failed:", err); + // Still set as authenticated since we have tokens + setStatus("auth"); + } cleanupAuthUrl(); return { ok: true }; @@ -645,9 +651,16 @@ export function AuthProvider({ children }) { useEffect(() => { if (hasKeycloakCallbackParams()) { - completeKeycloakLogin(); + completeKeycloakLogin().catch((err) => { + console.error("[Auth] SSO callback error:", err); + setAnon("SSO failed unexpectedly. Please try again."); + cleanupAuthUrl(); + }); } else { - restore(); + restore().catch((err) => { + console.error("[Auth] Restore error:", err); + setAnon(""); + }); } const onStorage = (e) => { if (e.key === "sociowire:auth") restore();