feat(gotrue): surface the sign-out reason on the signedOut event#1453
Open
spydon wants to merge 8 commits into
Open
feat(gotrue): surface the sign-out reason on the signedOut event#1453spydon wants to merge 8 commits into
spydon wants to merge 8 commits into
Conversation
Add AuthState.exception, populated when the user is signed out involuntarily because the session could not be recovered (an invalid or expired refresh token). It is null for an explicit signOut and for all other events, letting listeners tell the two apart without attaching an onError handler.
…ned-out-reason # Conflicts: # packages/gotrue/test/refresh_token_race_test.dart
Collaborator
|
Adding an |
The missing-data and session-expired paths called notifyException explicitly and then threw, and the surrounding catch notified again, so two errors hit onAuthStateChange. Throw without the explicit notify and let the catch be the single notification point. Add a test asserting exactly one error is emitted.
Replaces the `AuthState.exception` field with a typed `SignOutReason` (userInitiated, sessionExpired, sessionMissing) so listeners can tell an explicit sign out apart from an involuntary one without inspecting an exception. The reason is threaded through `notifyAllSubscribers` and set on every local sign-out path; it is still not broadcast across tabs. The involuntary recoverSession/setInitialSession exceptions now also carry stable `session_expired` / `session_missing` codes (added to `ErrorCode`, which is now exported) so the same reason is available on the stream error. Registers the new public symbols in sdk-compliance.yaml.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
AuthState.exception, populated when the user is signed out involuntarily because the session could not be recovered (an invalid or expired refresh token). It isnullfor an explicitsignOut()and for every event other thansignedOut.Why
Follow-up to the discussion on #1450. That PR stops
recoverSessionfrom double-reporting an expected sign-out as an uncaught stream error. The remaining concern was that a pureonAuthStateChangelistener then seessignedOutwithout knowing why the user was signed out, which removes the ability to handle it differently or notify the user.This restores that capability through the event itself, rather than through an error that only reaches listeners with an
onErrorhandler:How
AuthStategains a nullableexceptionfield.notifyAllSubscribersaccepts an optionalexceptionand threads it onto theAuthState._executeRefreshpasses the causingAuthExceptionwhen it signs the user out on a non-retryable refresh failure.The exception is intentionally not propagated across tabs via the broadcast channel, so it is always
nullwhenfromBroadcastistrue.Tests
signedOutevent carries the exception on an invalid refresh token.signedOutevent has no exception on an explicitsignOut.