Skip to content

fix(auth): emit a sessionMissing sign out for an unreadable stored session at startup - #2107

Merged
spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2599-auth-report-the-right-sign-out-reason-for-explicit-sign-outs
Oct 29, 2026
Merged

spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2599-auth-report-the-right-sign-out-reason-for-explicit-sign-outs

Conversation

@spydon

@spydon spydon commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

What

When the session persisted by an earlier run cannot be restored at startup, because the stored value cannot be parsed or is missing required data, the auth client now emits signedOut with SignOutReason.sessionMissing after initialSession(null). Before, the value was removed silently and listeners only saw initialSession(null), the same as a user who was never signed in. This matches the auth.session.sign_out_reason spec, which defines sessionMissing for this case.

A startup with nothing stored is unchanged and only emits initialSession(null).

How

  • _readPersistedSession reports whether it discarded a stored value.
  • _restoreSession then emits the sign out in a later event loop turn, so a listener that subscribes right after initialized completes, as await Supabase.initialize() followed by onAuthStateChange.listen does, still receives it after its initial event.
  • The event is skipped when a sign in or sign out happened in the meantime, and it is not broadcast to other tabs, since no other tab can hold the discarded value as its session.
  • supabase_flutter does nothing special for signedOut. The SupabaseClient listener resets the realtime token to the API key, which it already is with no session.

Scope

This is part 2 of SDK-2599 only. Part 1, the reason and exception for an explicit global or others sign out with a rejected refresh token, waits for the sign out spec in supabase/sdk#302 to be settled.

No public API changes, so sdk-compliance.yaml is unchanged.

Tests

session_persistence_test.dart no longer locks in the silent removal. It now covers an unparseable value, a session without user data, a session without an access token, a subscriber arriving once the client is initialized, a sign in that follows the restore, and a startup with nothing stored. The supabase_auth, supabase and supabase_flutter suites pass locally against the local stack.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 24 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between cdfd66c and 198685a.

Files selected for processing: 3
  • packages/supabase_auth/lib/src/auth_client.dart
  • packages/supabase_auth/lib/src/types/sign_out_reason.dart
  • packages/supabase_auth/test/session_persistence_test.dart
  • 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.

@github-actions github-actions Bot added the auth This issue or pull request is related to authentication label Oct 29, 2026
@spydon
spydon merged commit 79cd356 into main Oct 29, 2026
43 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-2599-auth-report-the-right-sign-out-reason-for-explicit-sign-outs branch October 29, 2026 18:26
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