Repository navigation
fix(gotrue,supabase): session persistence end to end - #394
Merged
Merged
Conversation
…rk reasons RetrieveSessionAsync destroyed the session on any refresh exception, so an offline app start wiped the persisted session for good. Only a refresh token the server rejects signs the user out now, same as RefreshToken already does, and being marked offline returns the session instead of throwing. Part of supabase#390
LoadSession passed a null load straight to UpdateSession, which fires SignedOut and in turn destroys the persistence - so a cold start with nothing saved emitted a spurious sign-out to every listener. Part of supabase#390
…immediately An expired session schedules the refresh timer at zero and a failed attempt rescheduled at zero again, so an offline start with an expired persisted session hammered the server in a tight loop. The retry now waits 30 seconds after a skipped or failed refresh; the defect predates this change but restoring sessions by default makes it reachable for everyone. Part of supabase#390
…n store Review follow-ups: the startup refresh and the auto-refresh timer could race the same single-use refresh token, with the loser destroying the session, and a session store that throws on load crashed startup. Concurrent refreshes now share the running attempt and a failing load is logged and skipped. Part of supabase#390
The interface and readme both promise it, but the client never called LoadSession, so after a restart every request went out with the anon key. Fixes supabase#390
Same 30 second wait, now traceable to AUTO_REFRESH_TICK_DURATION_MS instead of reading as an arbitrary number. Also drops two redundant identity asserts from the restore tests. Part of supabase#390
The shared refresh committed its result unconditionally, so a sign-out or a sign-in as somebody else while the call was in flight got overwritten by the old user's session, or signed the new user out on an invalid token. The originating refresh token is captured and the result dropped if it no longer matches, same as the auth-js commit guards. Also from review: RefreshToken is async again so guard failures surface as faulted tasks (the coalescing test now counts requests through a gated handler instead of comparing task identity), LoadSession clears the session when the store was emptied behind the client's back, and the never-produced ExpiredRefreshToken guard is gone. Part of supabase#390
An emptied store clears the session now, so the interface doc no longer describes it as a no-op. Part of supabase#390
The in-flight refresh was shared with any caller, so after a sign-out plus sign-in the new session could join the old session's stale attempt and see its outcome instead of refreshing. Attempts are now keyed to the refresh token they started for, and the whole session is captured once so the call can't mix the old refresh token with the new access token. Also restores the no-persistence LoadSession no-op that the emptied-store fix regressed. Part of supabase#390
http://localhost:1 opened a real socket; SupabaseOptions.HttpClient reaches the auth client, so the test now throws from a handler instead. Part of supabase#390
Adversarial review probes found three edges of the replaced-session guard: RetrieveSessionAsync returned null while a valid replacement session was live, RefreshSession threw NullReferenceException when a sign-out landed mid-refresh, and a destroyed session left its refresh token in the in-flight key. Part of supabase#390
Clearing lived in DestroySession, but SignOut and an emptied store reach UpdateSession(null) directly, so the token could outlive those. RefreshSession also re-read CurrentSession across its awaits and could throw NullReferenceException on a concurrent sign-out; it works from one snapshot now. Adds the missing regression test for the survivor return. Part of supabase#390
the gate only covered the dedup slot, so a sign-out could interleave with a refresh and get its session resurrected and re-persisted. session reads, commits and clears now happen under it, notifications stay outside.
gotrue checks nbf with no leeway and the docker clock drifts sub-second against the host, so the admin tests failed at random with bad_jwt.
CA2016 - the handler already has the token from SendAsync.
a refresh outside the timer left the old deadline armed, and a sign-in finishing during a slow store read got overwritten by the stale load.
Tr00d
approved these changes
Aug 31, 2026
Tr00d
left a comment
Contributor
There was a problem hiding this comment.
LGTM, well done.
One thing I would like to change: can you remove ## 9 from the migration guide? This is not a breaking change per se, and the goal of this guide is to help customers solve breaking changes that they will encounter while upgrading.
Wdyt?
Contributor
Author
|
fair point - a migration step whose only instruction is "do nothing" is not much of a step. removed 😄 |
Contributor
|
@fresh55 I had to rename the title to make it a bit more explicit and avoid the double-context as it wouldn't render well with release-please |
This was referenced Sep 5, 2026
This was referenced Sep 12, 2026
This was referenced Sep 29, 2026
2 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.
Fixes #390
gotrue: a failed refresh destroyed the session even on a plain network error, so an offline start signed the user out for good. Now only a server-rejected refresh token signs out, same as supabase-js. While in there: an empty session store no longer fires a spurious SignedOut, a failed refresh waits one 30s tick instead of hot-looping (the supabase-js cadence), concurrent refreshes share one attempt and a refresh that finishes after the session was replaced is discarded instead of clobbering it, and a store that throws on load doesn't crash startup.
supabase: InitializeAsync now restores the persisted session, like the readme always said.