Skip to content

fix(auth): sign out as asked when a global or others sign out finds the refresh token rejected - #2110

Merged
spydon merged 1 commit into
mainfrom
lukasklingsbo/sdk-2602-auth-sign-out-reason-and-error-for-an-explicit-global-or
Oct 30, 2026
Merged

spydon merged 1 commit into
mainfrom
lukasklingsbo/sdk-2602-auth-sign-out-reason-and-error-for-an-explicit-global-or

Conversation

@spydon

@spydon spydon commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Resolves SDK-2602.

Implements the global and others part of the sign out spec in supabase/sdk#302, as amended by supabase/sdk#302 (review).

Problem

signOut(scope: global | others) refreshed an expired access token through getSession(). When the server rejected the refresh token, that regular refresh signed the device out with SignOutReason.sessionExpired, even though the user asked to sign out, and signOut rethrew the raw refresh error. The app could not tell that the other sessions were left alive.

Changes

  • global and others now refresh an expired access token themselves instead of through getSession(). A failed refresh emits no events.
  • When the server rejects the refresh token, the device is signed out with SignOutReason.userInitiated, no /logout request is sent, and signOut throws the new AuthSessionsNotRevokedException. It carries the requested scope and the refresh error as cause, and its message says to sign in again to revoke the other sessions.
  • A transient refresh failure keeps the session and throws as before, and an access token still inside its expiry margin is still used to revoke.
  • Registered AuthSessionsNotRevokedException as a supporting symbol of auth.session.sign_out.
  • Updated the signOut dartdoc, the signOut() section of MIGRATION.md and the auth setup skill.

Deviation from the review: a successful refresh is stored

The review asks for the refresh token to be kept in memory, with the refreshed session not stored. This PR stores a successful refresh and emits tokenRefreshed, like a regular refresh does. Only a failed refresh stays in memory and emits nothing.

The reason is refresh token rotation. Once a refresh token has been rotated, reusing it after the reuse interval (10 seconds by default) makes the auth server end the whole session and answer refresh_token_already_used (internal/tokens/service.go in supabase/auth). If the refreshed session were not stored:

  • with others, which keeps the local session, the next refresh of the stored token would sign this device out,
  • with global, a failed /logout that keeps the session for a retry would leave a session that is signed out on its next refresh.

local is unaffected because it has already removed the session when it refreshes. If this sounds right, the spec in supabase/sdk#302 should say the same for global and others.

Tests

  • Both scopes: a rejected refresh emits a single signedOut with SignOutReason.userInitiated, throws AuthSessionsNotRevokedException with the scope and cause, and sends no /logout request.
  • Both scopes: a successful refresh is stored and emits tokenRefreshed before the sessions are revoked.
  • The existing transient failure, expiry margin and concurrent sign in tests still pass unchanged.

Summary by CodeRabbit

  • New Features
    • Sign-out now reports when the device has been signed out but the server could not revoke other sessions, using AuthSessionsNotRevokedException.
    • When a refresh token is rejected during global or other-device sign-out, the current device is signed out before the exception is thrown.
  • Documentation
    • Updated sign-out guidance to explain the behavior when a refresh token is rejected.

@github-actions github-actions Bot added the auth This issue or pull request is related to authentication label Oct 29, 2026
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 95a2fc5 and 021cb57.

Files selected for processing: 7
  • MIGRATION.md
  • packages/supabase_auth/lib/src/auth_client.dart
  • packages/supabase_auth/lib/src/types/auth_exception.dart
  • packages/supabase_auth/test/sign_out_scope_test.dart
  • packages/supabase_flutter/skills/supabase-flutter-auth-setup/SKILL.md
  • sdk-compliance.yaml
  • skills_src/auth-setup/SKILL.md.tmpl

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

Walkthrough

Sign-out now refreshes expired sessions through a dedicated path. If the server rejects the refresh token, the client signs out this device and throws AuthSessionsNotRevokedException. The exception records the requested scope and underlying cause.

Changes: Sign-out refresh handling

Layer / File(s) Summary
Refresh and sign-out behavior
packages/supabase_auth/lib/src/types/auth_exception.dart, packages/supabase_auth/lib/src/auth_client.dart, packages/supabase_auth/test/sign_out_scope_test.dart, MIGRATION.md, packages/supabase_flutter/skills/supabase-flutter-auth-setup/SKILL.md, skills_src/auth-setup/SKILL.md.tmpl, sdk-compliance.yaml
AuthSessionsNotRevokedException carries the sign-out scope and refresh error cause. Sign-out refreshes expired sessions before revocation. If refresh-token rejection occurs and the session has not changed, the client signs out locally and throws the new exception. Tests cover rejected and successful refresh paths. Documentation and SDK compliance metadata describe the exception and behavior.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant AuthClient
  participant AuthAPI
  participant AuthEventStream
  Caller->>AuthClient: Request sign-out
  AuthClient->>AuthAPI: Refresh expired session
  alt Refresh token rejected
    AuthClient->>AuthEventStream: Emit userInitiated sign-out
    AuthClient-->>Caller: Throw AuthSessionsNotRevokedException
  else Refresh succeeds
    AuthClient->>AuthEventStream: Emit tokenRefreshed
    AuthClient->>AuthAPI: Revoke sessions with refreshed access token
    AuthClient->>AuthEventStream: Emit userInitiated sign-out
    AuthClient-->>Caller: Complete sign-out
  end
Loading

Possibly related PRs

Suggested labels: auth

Merge Risk: Low · up to 021cb

A concurrent automatic refresh can occasionally leave a session active after sign-out fails. The risk is bounded but warrants owner awareness or follow-up.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: handling rejected refresh tokens during global or others sign-out by signing out locally as requested.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 0 files. (7 skipped: 7 unsupported.)

Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • 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

Comment @coderabbitai help to get the list of available commands.

@spydon
spydon merged commit f084401 into main Oct 30, 2026
48 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-2602-auth-sign-out-reason-and-error-for-an-explicit-global-or branch October 30, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth This issue or pull request is related to authentication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant