-
-
Notifications
You must be signed in to change notification settings - Fork 213
fix(gotrue): Ensure a single initialSession
is emitted.
#975
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
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,24 +58,26 @@ class SupabaseAuth with WidgetsBindingObserver { | |
final persistedSession = await _localStorage.accessToken(); | ||
if (persistedSession != null) { | ||
try { | ||
Supabase.instance.client.auth.setInitialSession(persistedSession); | ||
await Supabase.instance.client.auth | ||
.setInitialSession(persistedSession); | ||
shouldEmitInitialSession = false; | ||
} catch (error, stackTrace) { | ||
Supabase.instance.log(error.toString(), stackTrace); | ||
} | ||
} | ||
} | ||
if (shouldEmitInitialSession) { | ||
Supabase.instance.client.auth | ||
// ignore: invalid_use_of_internal_member | ||
.notifyAllSubscribers(AuthChangeEvent.initialSession); | ||
} | ||
Comment on lines
+69
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving this before the deep link handling to ensure the empty initial session is emitted first. |
||
_widgetsBindingInstance?.addObserver(this); | ||
|
||
if (options.detectSessionInUri) { | ||
await _startDeeplinkObserver(); | ||
} | ||
|
||
// Emit a null session if the user did not have persisted session | ||
if (shouldEmitInitialSession) { | ||
Supabase.instance.client.auth | ||
// ignore: invalid_use_of_internal_member | ||
.notifyAllSubscribers(AuthChangeEvent.initialSession); | ||
} | ||
} | ||
|
||
/// Recovers the session from local storage. | ||
|
@@ -199,7 +201,12 @@ class SupabaseAuth with WidgetsBindingObserver { | |
// initial link was done with getInitialAppLink. Being in this catch | ||
// handler means we are in at least version 6.0.0, meaning we do not | ||
// need to handle the initial link manually. | ||
// https://pub.dev/packages/app_links/changelog | ||
// | ||
// app_links claims that the initial link will be included in the | ||
// `uriLinkStream`, but that is not the case for web | ||
if (kIsWeb) { | ||
uri = await (_appLinks as dynamic).getInitialLink(); | ||
} | ||
} | ||
if (uri != null) { | ||
await _handleDeeplink(uri); | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason the
shouldEmitInitialSession
was never set to false, causing the initialSession to be emitted every single time.