Skip to content

Commit 6e08050

Browse files
Zexiclaude
authored andcommitted
fix: redirect to home on 401 instead of showing error boundary
When server credentials change, stale browser sessions get 401 on API calls. Intercept all 401 responses globally and navigate to "/" so the user can re-authenticate, rather than showing an unrecoverable "Something went wrong". Using a never-resolving Promise prevents the SDK error from propagating to the error boundary before navigation completes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b674c5a commit 6e08050

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

packages/app/src/entry.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ if (import.meta.env.VITE_SENTRY_DSN) {
153153
})
154154
}
155155

156+
// Intercept 401 responses: if credentials are stale and we're not on the home
157+
// page already, navigate to "/" so the user can re-authenticate.
158+
const _nativeFetch = globalThis.fetch.bind(globalThis)
159+
const _interceptedFetch = async (input: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]): Promise<Response> => {
160+
const response = await _nativeFetch(input, init)
161+
if (response.status === 401 && window.location.pathname !== "/") {
162+
window.location.href = "/"
163+
return new Promise<Response>(() => {})
164+
}
165+
return response
166+
}
167+
Object.assign(_interceptedFetch, globalThis.fetch)
168+
globalThis.fetch = _interceptedFetch as unknown as typeof fetch
169+
156170
if (root instanceof HTMLElement) {
157171
const auth = authFromToken(new URLSearchParams(location.search).get("auth_token"))
158172
clearAuthToken()

0 commit comments

Comments
 (0)