fix(auth): prevent session deletion on proactive refresh failure when token still valid#2146
fix(auth): prevent session deletion on proactive refresh failure when token still valid#21467ttp wants to merge 2 commits intosupabase:masterfrom
Conversation
… token still valid
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe PR removes the code path that unconditionally deleted the stored session when a non-retryable error occurred during _callRefreshToken. On non-retryable refresh failures the client now surfaces the error but does not call this._removeSession(), leaving session data in storage intact. Tests were added to verify that a non-retryable AuthError from _refreshAccessToken does not remove the stored session. Sequence Diagram(s)(omitted) Assessment against linked issues
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@supabase/auth-js
@supabase/functions-js
@supabase/postgrest-js
@supabase/realtime-js
@supabase/storage-js
@supabase/supabase-js
commit: |
b0edb29 to
51b4fb1
Compare
|
Thank you @7ttp ! I removed the additional logic and added a test!! |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/core/auth-js/test/GoTrueClient.test.ts`:
- Around line 494-499: The test currently asserts that client.getSession()
returns data.session === null on proactive-refresh failure; update the
assertions to verify that the existing seeded session is returned instead and
that storage remains intact. Specifically, in the GoTrueClient.test where
getSession() is called, replace the expect(data.session).toBeNull() with an
assertion that data.session matches the seeded session object (or at least has
the expected access_token/uid/expires_at values) and add an assertion that the
stored refresh token (or session data in whatever storage mock you used) is
still present, ensuring client.getSession() returns the valid session even when
proactive refresh errors.
ℹ️ Review info
Configuration used: Central YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Cache: Disabled due to Reviews > Disable Cache setting
Disabled knowledge base sources:
- Linear integration is disabled
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/core/auth-js/src/GoTrueClient.tspackages/core/auth-js/test/GoTrueClient.test.ts
💤 Files with no reviewable changes (1)
- packages/core/auth-js/src/GoTrueClient.ts
What this PR introduces
Removes the
_removeSession()call from_callRefreshToken. This prevents sessions from being deleted from storage on proactive refresh failure when the access token is still valid (e.g., within the 90sEXPIRY_MARGIN_MSwindow).No additional logic, just a fix to ensure the session remains recoverable.
Why is this change needed
Previously, if a proactive token refresh failed with a non-retryable error (such as
invalid_grant), the session was permanently deleted from storage even though the access token was still technically valid. This caused users to be silently logged out until they re-authenticated, and made recovery impossible until a full app reload._callRefreshTokenis a low-level helper — it shouldn't own session lifecycle decisions. Callers that need to clean up already do so independently (_recoverAndRefreshhas its own_removeSession()call for non-retryable errors). Removing the call here lets__loadSession(thegetSession()path) degrade gracefully — returning the error without nuking a still-valid session.Changes
_removeSession()call from_callRefreshToken._recoverAndRefresh) remains unchanged.Related