Skip to content

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 3 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions packages/supabase_flutter/lib/src/supabase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member Author

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.

} 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
Copy link
Member Author

Choose a reason for hiding this comment

The 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.
Expand Down Expand Up @@ -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);
Expand Down
Loading