Repository navigation
feat(gotrue): surface the sign-out reason on the signedOut event #1453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7b55eec
fix(gotrue): avoid duplicate auth error on recoverSession with invali…
spydon 2aa1d1d
Merge branch 'main' into fix/recover-session-duplicate-auth-error
spydon f59a650
fix(gotrue): scope recoverSession fix to the refresh path only
spydon ad56b14
refactor(gotrue): move recoverSession refresh call outside the catch
spydon c0f4145
feat(gotrue): surface the sign-out reason on the signedOut event
spydon 4d08f78
docs(gotrue): tighten recoverSession comment on the refresh path
spydon 18fdc04
Merge branch 'fix/recover-session-duplicate-auth-error' into feat/sig…
spydon 510262d
fix(gotrue): await refresh in recoverSession to keep it in stack traces
spydon 9cf40b2
Merge branch 'fix/recover-session-duplicate-auth-error' into feat/sig…
spydon cd68201
fix(gotrue): keep recoverSession and caller in the stack trace on ref…
spydon 8bc73c3
Merge branch 'fix/recover-session-duplicate-auth-error' into feat/sig…
spydon 934b46c
test(gotrue): drop redundant comment in wrong refresh token test
spydon b3c3574
Merge branch 'fix/recover-session-duplicate-auth-error' into feat/sig…
spydon 946f200
fix(gotrue): stop emitting recoverSession errors to the stream twice
spydon d9eb033
fix(gotrue): stop emitting recoverSession errors to the stream twice
spydon 5d6c8e1
Merge branch 'fix/recover-session-duplicate-auth-error' into feat/sig…
spydon 19f7d2d
refactor(gotrue): use a typed SignOutReason instead of an exception
spydon 48b5746
Merge remote-tracking branch 'origin/main' into feat/signed-out-reason
spydon 5f34275
docs(gotrue): clarify onError note and link error codes from SignOutR…
spydon 479456e
chore: declare sign_out_reason capability in sdk-compliance
spydon 967471c
Merge branch 'main' into feat/signed-out-reason
spydon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,37 @@ | ||
| import 'package:gotrue/src/constants.dart'; | ||
| import 'package:gotrue/src/types/session.dart'; | ||
| import 'package:gotrue/src/types/sign_out_reason.dart'; | ||
|
|
||
| class AuthState { | ||
| final AuthChangeEvent event; | ||
| final Session? session; | ||
|
|
||
| /// Why the user was signed out, when [event] is | ||
| /// [AuthChangeEvent.signedOut]. | ||
| /// | ||
| /// Lets listeners tell an explicit [GoTrueClient.signOut] apart from an | ||
| /// involuntary sign out, such as an invalid or expired refresh token, directly | ||
| /// from the `signedOut` event rather than from the matching stream error. An | ||
| /// `onError` handler is still needed to catch the other exceptions emitted on | ||
| /// the stream. It is `null` for every event other than | ||
| /// [AuthChangeEvent.signedOut] and for `signedOut` events received from | ||
| /// another tab via `web.BroadcastChannel`. | ||
| final SignOutReason? signOutReason; | ||
|
|
||
| /// Whether this state was broadcasted via `web.BroadcastChannel` on web from | ||
| /// another tab or window. | ||
| final bool fromBroadcast; | ||
|
|
||
| const AuthState(this.event, this.session, {this.fromBroadcast = false}); | ||
| const AuthState( | ||
| this.event, | ||
| this.session, { | ||
| this.fromBroadcast = false, | ||
| this.signOutReason, | ||
| }); | ||
|
|
||
| @override | ||
| String toString() { | ||
| return 'AuthState(event: ${event.name}, session: $session, fromBroadcast: $fromBroadcast)'; | ||
| return 'AuthState(event: ${event.name}, session: $session, ' | ||
| 'fromBroadcast: $fromBroadcast, signOutReason: ${signOutReason?.name})'; | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /// The reason why an [AuthChangeEvent.signedOut] event was emitted. | ||
| /// | ||
| /// Available on [AuthState.signOutReason] and lets listeners distinguish an | ||
| /// explicit sign out from an involuntary one, such as an expired session, | ||
| /// without inspecting error messages. | ||
| enum SignOutReason { | ||
| /// The user explicitly signed out by calling [GoTrueClient.signOut]. | ||
| userInitiated, | ||
|
|
||
| /// The session could no longer be refreshed because its refresh token was | ||
| /// rejected (invalid or expired), so the session was removed. | ||
| /// | ||
| /// Matches the [ErrorCode.sessionExpired] thrown on the stream. | ||
| sessionExpired, | ||
|
|
||
| /// A stored session could not be recovered because it was missing required | ||
| /// data, so the session was removed. | ||
| /// | ||
| /// Matches the [ErrorCode.sessionMissing] thrown on the stream. | ||
| sessionMissing, | ||
| } | ||
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.