Repository navigation
fix(auth): sign out as asked when a global or others sign out finds the refresh token rejected - #2110
Conversation
…he refresh token rejected
|
No actionable comments were generated in the recent review.
|
| 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:
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
Possibly related PRs
- supabase/supabase-flutter#2037: Changes the same sign-out refresh path and rejected-refresh outcome.
- supabase/supabase-flutter#2053: Changes the same global and others sign-out refresh path, with a different rejected-refresh outcome.
- supabase/supabase-flutter#2073: Documents the same rejected-refresh behavior for global and others sign-out.
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: 
5
-
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.
Comment @coderabbitai help to get the list of available commands.
Resolves SDK-2602.
Implements the
globalandotherspart 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 throughgetSession(). When the server rejected the refresh token, that regular refresh signed the device out withSignOutReason.sessionExpired, even though the user asked to sign out, andsignOutrethrew the raw refresh error. The app could not tell that the other sessions were left alive.Changes
globalandothersnow refresh an expired access token themselves instead of throughgetSession(). A failed refresh emits no events.SignOutReason.userInitiated, no/logoutrequest is sent, andsignOutthrows the newAuthSessionsNotRevokedException. It carries the requestedscopeand the refresh error ascause, and its message says to sign in again to revoke the other sessions.AuthSessionsNotRevokedExceptionas a supporting symbol ofauth.session.sign_out.signOutdartdoc, thesignOut()section ofMIGRATION.mdand 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.goin supabase/auth). If the refreshed session were not stored:others, which keeps the local session, the next refresh of the stored token would sign this device out,global, a failed/logoutthat keeps the session for a retry would leave a session that is signed out on its next refresh.localis 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 forglobalandothers.Tests
signedOutwithSignOutReason.userInitiated, throwsAuthSessionsNotRevokedExceptionwith the scope and cause, and sends no/logoutrequest.tokenRefreshedbefore the sessions are revoked.Summary by CodeRabbit
AuthSessionsNotRevokedException.