Skip to content

fix(auth): sign out after a global signOut that a refresh overlapped - #2263

Merged
spydon merged 1 commit into
supabase:mainfrom
Franklyn-R-Silva:fix/auth-global-sign-out-during-refresh
Dec 3, 2026
Merged

spydon merged 1 commit into
supabase:mainfrom
Franklyn-R-Silva:fix/auth-global-sign-out-during-refresh

Conversation

@Franklyn-R-Silva

@Franklyn-R-Silva Franklyn-R-Silva commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

signOut(scope: global) now signs this device out when a refresh of the same session landed while the logout request was in flight. Before, the refresh changed the stored tokens and the session version, so the device stayed signed in after the server had revoked its session.

Closes #2262

  • After the logout, the device signs out when the stored session is still the revoked server session: it holds the same tokens, or the same session_id claim in its access token. A refresh keeps the session_id and a new sign-in gets a new one, so a sign-in or sign-out that happened during the request still wins, as the signOut doc says.
  • An access token without a session_id claim falls back to the token comparison, so the existing test that keeps a sign-in made during the request passes unchanged.
  • The same check covers the expired-session path, where _refreshForSignOut hands back an unstored session because a concurrent refresh stored one first.
  • New tests: a refresh completing during the logout signs out with userInitiated, and fails without the fix; a new session of the same user, with another session_id, stays signed in.

Summary by CodeRabbit

  • Bug Fixes
    • Global sign-out now handles concurrent session refreshes more reliably, signing out the refreshed session when it belongs to the revoked server session.
    • A different session that becomes active while sign-out is in progress remains signed in.

signOut(scope: global) removed the local session only when the stored
tokens and the session version were unchanged after the logout
request. A refresh of the same session that landed while the request
was in flight changed both, so the server revoked every session while
the device stayed signed in with no signedOut event, until its dead
refresh token failed about an hour later.

The device now signs out when the stored session is still the revoked
server session: the same tokens, or the same session_id claim, which a
refresh keeps and a new sign-in changes.
Copilot AI balanced review requested due to automatic review settings December 2, 2026 18:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Global sign-out now revokes the server session before checking local state. It clears the current session when its tokens or non-null session_id match the revoked session. Tests cover concurrent refresh and session replacement.

Changes: Global sign-out

Layer / File(s) Summary
Match and clear the revoked session
packages/supabase_auth/lib/src/auth_client.dart, packages/supabase_auth/test/sign_out_scope_test.dart
Global sign-out checks whether the current session matches the revoked session by tokens or session_id. Tests verify that a refreshed version of that session is cleared, while a replacement session remains signed in.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

Suggested labels: auth

Merge Risk: Minimal · up to 8e20d

Global sign-out now clears the device when a token refresh overlaps the logout request. A new sign-in during the request stays signed in. No actionable merge-blocking risk was found, and tests cover both behaviors.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(auth): sign out after a global signOut that a refresh overlapped" matches the main change. The PR makes global sign-out clear the local session when a token refresh completes during the…
Linked Issues check Passed [#2262] The issue requires that a global sign-out signs out the device with SignOutReason.userInitiated when a refresh of the same session completes during the logout request. A new sign-in during the…
Out of Scope Changes check Passed All changes in auth_client.dart and sign_out_scope_test.dart relate to the global sign-out race in #2262. The changes add the session_id comparison helpers (_isSameServerSession, _sessionIdOf). They r…
Full details: Title check

Explanation

The title "fix(auth): sign out after a global signOut that a refresh overlapped" matches the main change. The PR makes global sign-out clear the local session when a token refresh completes during the logout request. The title names the auth area, the fix, and the triggering case. It is specific and does not use vague terms.

Full details: Linked Issues check

Explanation

[#2262] The issue requires that a global sign-out signs out the device with SignOutReason.userInitiated when a refresh of the same session completes during the logout request. A new sign-in during the request must stay signed in. The PR adds _isSameServerSession in auth_client.dart. It treats the stored session as the revoked server session when the access and refresh tokens match, or when the access-token session_id claims are equal and non-null. A refresh keeps session_id, so the device signs out. A new sign-in gets a new session_id, so it stays signed in. The PR also applies this check to the expired-session path in _refreshForSignOut. The PR adds two tests in sign_out_scope_test.dart. One covers a refresh during logout and expects tokenRefreshed, then signedOut with userInitiated. The other covers a replacement session of the same user with a different session_id and expects it to stay signed in. Limitation: the source diff could not be read. The head file was readable, but its signOut section was beyond the output limit. This verdict relies on the supplied raw summary and PR description, which describe the logic consistently with the issue. An access token without a session_id claim falls back to token comparison. A refresh of such a token would not be detected. The issue does not address that case.

Full details: Out of Scope Changes check

Explanation

All changes in auth_client.dart and sign_out_scope_test.dart relate to the global sign-out race in #2262. The changes add the session_id comparison helpers (_isSameServerSession, _sessionIdOf). They reorder the server revocation before the local session check and remove the token-only comparison and session-version snapshot check that caused the bug. The changes also add two regression tests. No unrelated behavior, public API declarations, or other files appear in the supplied summary. The source diff could not be read to confirm this directly, so the verdict relies on the supplied summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4e82a79 and 8e20d15.

Files selected for processing: 2

  • packages/supabase_auth/lib/src/auth_client.dart
  • packages/supabase_auth/test/sign_out_scope_test.dart

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

@spydon
spydon merged commit b8ca96c into supabase:main Dec 3, 2026
69 of 70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

signOut(scope: global) leaves the device signed in when a token refresh lands during the request

3 participants