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);
|
setAuthFromTokens(t);
|
||||||
scheduleAutoRefresh();
|
scheduleAutoRefresh();
|
||||||
|
|
||||||
const w = await whoami(t.access_token);
|
try {
|
||||||
if (!w.ok || !w.authenticated) {
|
const w = await whoami(t.access_token);
|
||||||
setAnon("SSO login desynced. Please login again.");
|
if (!w.ok || !w.authenticated) {
|
||||||
cleanupAuthUrl();
|
setAnon("SSO login desynced. Please login again.");
|
||||||
return { ok: false, reason: "whoami_failed" };
|
cleanupAuthUrl();
|
||||||
}
|
return { ok: false, reason: "whoami_failed" };
|
||||||
|
}
|
||||||
|
|
||||||
setUser(w.username ? { username: w.username } : null);
|
setUser(w.username ? { username: w.username } : null);
|
||||||
setStatus("auth");
|
setStatus("auth");
|
||||||
await refreshProfile(t.access_token);
|
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();
|
cleanupAuthUrl();
|
||||||
return { ok: true };
|
return { ok: true };
|
||||||
|
|
@ -645,9 +651,16 @@ export function AuthProvider({ children }) {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hasKeycloakCallbackParams()) {
|
if (hasKeycloakCallbackParams()) {
|
||||||
completeKeycloakLogin();
|
completeKeycloakLogin().catch((err) => {
|
||||||
|
console.error("[Auth] SSO callback error:", err);
|
||||||
|
setAnon("SSO failed unexpectedly. Please try again.");
|
||||||
|
cleanupAuthUrl();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
restore();
|
restore().catch((err) => {
|
||||||
|
console.error("[Auth] Restore error:", err);
|
||||||
|
setAnon("");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const onStorage = (e) => {
|
const onStorage = (e) => {
|
||||||
if (e.key === "sociowire:auth") restore();
|
if (e.key === "sociowire:auth") restore();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue