Fix OAuth callback crash causing black page
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
0d58ca25ab
commit
18b55c3f49
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue