2026-11-21 — Signed-in page loads no longer block the Supabase client
The auth state handler awaited a profile query from inside the auth callback. While a stored session is being restored this blocks the client for good: header shows logged-out, no client query runs. Fixed; regression test added.
Related: #568 (closed 2026-04-17 with a timeout-and-recover workaround, #570 and #573).
What happened
Found while driving the consent gate in a browser. With a valid session cookie, the page rendered the logged-out header and the browser sent no request to Supabase at all; the auth lock lock:sb-…-auth-token was still held after 9 seconds.
Cause, read in @supabase/auth-js 2.101.1 (dist/main/GoTrueClient.js): restoring a stored session (_recoverAndRefresh) awaits every onAuthStateChange subscriber for the SIGNED_IN event, and getSession() — which every query calls to get its token — first awaits that same restore. The handler in apps/web/lib/auth-context.tsx awaited supabase.from("profiles")… for SIGNED_IN. Each waits for the other.
The #568 workaround (6 s timeout on getUser(), then local sign-out and redirect) cannot recover from this, because the local sign-out waits on the same blocked client.
Scope of the evidence
Reproduced in a local production build of the current lockfile with a stubbed backend, and in a unit test that models the two awaits. Not observed on the live site — no test login was available. Whether April's live verification of #568 ran on an earlier auth-js version was not checked.
Fix
apps/web/lib/auth-context.tsx: the onAuthStateChange callback is synchronous. The profile query and the stale-session recovery run in a new task (setTimeout(…, 0)), outside the callback, as the Supabase documentation for onAuthStateChange prescribes.
Verification
apps/web/lib/auth-context.test.tsx: fails on the old handler (still loading after 2 s), passes on the new one.- Browser, same build and stub as above: header shows the signed-in pseudonym, profile and consent status requests are sent.
Follow-up
- Check on the live site with a real login after deployment.
apps/mobile/hooks/useAuth.tsx:85-89callsfetchProfilefrom itsonAuthStateChangehandler without awaiting it; not changed, not tested.
2026-11-22 — Consent migration applied to the live database
20261121_user_consents.sql is live. Existing accounts are locked until their owners confirm the consents in the app. Verified before and after in rolled-back transactions.
2026-11-21 — Consent records validated on the server; accounts without consent are locked
Rework of the consent migration after the external review in #715. The database now validates the full consent set against registered versions, sets the time itself and locks accounts without valid consents. Not applied to the live database.