Skip to content

feat(gotrue): add typed SignOutReason on the signedOut AuthState - #1465

Closed
spydon wants to merge 1 commit into
mainfrom
feat/gotrue-sign-out-reason
Closed

spydon wants to merge 1 commit into
mainfrom
feat/gotrue-sign-out-reason

Conversation

@spydon

@spydon spydon commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What

Adds a typed SignOutReason to the signedOut auth state so listeners can tell an explicit sign out apart from an involuntary one (e.g. an expired session) without inspecting error messages.

This is an alternative to attaching a raw AuthException to AuthState (proposed in #1453). A small, client-owned enum gives a stable, discoverable contract, keeps AuthState a clean value type, and avoids dragging the exception hierarchy into its toString/equality.

Changes

  • New SignOutReason enum: userInitiated, sessionExpired, sessionMissing.
  • AuthState.signOutReason (nullable) — set only on signedOut, null otherwise and for signedOut events received from another tab via BroadcastChannel.
  • Threaded through notifyAllSubscribers and set on every local sign-out path:
    • explicit signOut() → userInitiated
    • non-retryable refresh failure in _executeRefresh → sessionExpired
    • recoverSession/setInitialSession with an expired/missing session → sessionExpired / sessionMissing
  • The reason is intentionally not broadcast across tabs.
  • Addresses the recover-method gap from the #1453 review: the involuntary recoverSession/setInitialSession exceptions previously carried only a human-readable message. They now also carry stable session_expired / session_missing codes (added to ErrorCode), so the same reason is available whether you read it from the signedOut state or from the stream error.

Tests

Extended token_refresh_race_test.dart to assert the reason on a refresh failure, an explicit sign out, and recoverSession with an expired session.

Adds a `SignOutReason` enum (userInitiated, sessionExpired, sessionMissing)
exposed via `AuthState.signOutReason`, so listeners can tell an explicit
sign out apart from an involuntary one without inspecting error messages.

The reason is threaded through `notifyAllSubscribers` and set on every
local sign-out path: explicit `signOut`, a non-retryable refresh failure,
and `recoverSession`/`setInitialSession` when the stored session is expired
or missing data. It is intentionally not broadcast across tabs.

The involuntary `recoverSession`/`setInitialSession` exceptions now also
carry stable `session_expired` / `session_missing` error codes (added to
`ErrorCode`) so the same reason is available on the stream error.
@spydon
spydon requested a review from a team as a code owner June 24, 2026 14:44
@github-actions github-actions Bot added the auth This issue or pull request is related to authentication label Jun 24, 2026
@spydon spydon closed this Jun 24, 2026
@spydon
spydon deleted the feat/gotrue-sign-out-reason branch July 7, 2026 07:42
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