Repository navigation
fix(auth): stop profile screens loading empty after a 401 (#579) - #595
Merged
Merged
Conversation
Every profile editor rendered blank for a signed-in user whose access token needed a refresh. A single load of /profile/resume 401'd on /profiles/general, /profiles/employment, /profiles/slug/history, /profiles/import/data, /resume/has-uploaded and /profiles/widgets/general-info, and only some of them were ever retried — the rest stayed failed for the life of the page while the same endpoints returned full data to a hand-rolled fetch with the same session. Three independent gaps, all fixed here: 1. `retry: 2` retried 401s against the same stale client, burning all three attempts inside ~3s so nothing was left once the refresh landed. Queries now use a status-aware policy that gives up immediately on deterministic 4xx and keeps the exponential backoff for network and 5xx failures. 2. The recovery invalidation fired only on the isLoading true->false transition, so a token that expired while the tab was open never triggered it. It now fires on every access_token change. 3. That invalidation filtered by a hand-maintained list of ten query-key prefixes, but scf-core registers 30+ roots — `resume`, `idVerification`, `user-profiles`, `['scaffald','skills',...]` and a dozen more were never covered. The allow-list is gone; an allow-list that must be updated whenever a hook is added will drift again, not having one cannot. Adds a single-flight, cooldown-guarded session refresh on 401. The same load that produced these 401s also issued nine POST /auth/v1/token because every failing query kicked its own refresh; the lock collapses a burst into one. Co-Authored-By: Claude Opus 5 <[email protected]>
15 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #579. First of the profile-building audit rollup (#594) — the epic sequences this one alone, because it is the root of the empty-form reports and it changes how every other client-side symptom presents.
The bug
Every profile editor rendered blank for a signed-in user whose access token needed a refresh. One load of
/profile/resume:Only three unrelated queries were retried; the rest stayed failed for the life of the page. The same endpoint with the same session, fetched by hand from the page console, returned the user's full record.
Three gaps, all fixed here
retry: 2retried 401s against the same stale client. All three attempts burned inside ~3s, so nothing was left by the time Supabase refreshed. Replaced with a status-aware policy (provider/react-query/retry.ts): deterministic 4xx give up immediately, network and 5xx keep the exponential backoff, 429 stays retryable.Recovery invalidation fired only on the
isLoadingtrue→false transition. A token that expired while the tab was open produced no transition, so nothing refetched. Now keyed on the access token itself, which covers the initial load and every later refresh.That invalidation filtered by a hand-maintained list of ten query-key prefixes, against 30+ roots scf-core actually registers —
resume,idVerification,user-profiles,['scaffald','skills',…]and a dozen more were never covered. The allow-list is gone. One that must be updated whenever a hook is added will drift again; not having one cannot.Also adds a single-flight, cooldown-guarded refresh on 401. That same load issued nine
POST /auth/v1/tokenbecause every failing query kicked its own refresh; the lock collapses a burst into one, and the 10s cooldown stops a dead refresh token becoming a request loop.Tests
33 assertions, all new or updated:
retry.test.ts— per-status policy, including the "never retries a 401" regression.requestSessionRefresh.test.ts— 20 concurrent 401s produce one refresh; cooldown holds; a rejected refresh is swallowed rather than surfacing as a second error.jobs-sdk-context.test.tsx— adds the five key roots the old allow-list missed, plus mid-session token refresh and a no-op re-render case.One existing assertion inverted deliberately:
['unrelated','thing']used to assert not invalidated, to prove the allow-list was selective. Everything in the cache was fetched with the credential that just changed, so everything is now invalidated; react-query only refetches what is mounted.Note for reviewers
This branch was built against submodule pointers synced to
main(packages/sdk→2ae9506,packages/ui→fdaa0d4). The worktree had them stale-behind, which produced 35 phantomtscerrors and a failingscf-core:buildin pre-push; after syncing, scf-core typechecks clean at 0 errors. No submodule pointer change is included in this PR.🤖 Generated with Claude Code