Skip to content

Commit 6323f9f

Browse files
authored
fix(gotrue): Ensure a single initialSession is emitted. (#975)
* fix: make sure duplicate initial session does not happen * Make sure the initial link is included for web * Update the comment on ignoreing initial link for latest app_link
1 parent ff26d93 commit 6323f9f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

packages/supabase_flutter/lib/src/supabase_auth.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,26 @@ class SupabaseAuth with WidgetsBindingObserver {
5858
final persistedSession = await _localStorage.accessToken();
5959
if (persistedSession != null) {
6060
try {
61-
Supabase.instance.client.auth.setInitialSession(persistedSession);
61+
await Supabase.instance.client.auth
62+
.setInitialSession(persistedSession);
63+
shouldEmitInitialSession = false;
6264
} catch (error, stackTrace) {
6365
Supabase.instance.log(error.toString(), stackTrace);
6466
}
6567
}
6668
}
69+
if (shouldEmitInitialSession) {
70+
Supabase.instance.client.auth
71+
// ignore: invalid_use_of_internal_member
72+
.notifyAllSubscribers(AuthChangeEvent.initialSession);
73+
}
6774
_widgetsBindingInstance?.addObserver(this);
6875

6976
if (options.detectSessionInUri) {
7077
await _startDeeplinkObserver();
7178
}
7279

7380
// Emit a null session if the user did not have persisted session
74-
if (shouldEmitInitialSession) {
75-
Supabase.instance.client.auth
76-
// ignore: invalid_use_of_internal_member
77-
.notifyAllSubscribers(AuthChangeEvent.initialSession);
78-
}
7981
}
8082

8183
/// Recovers the session from local storage.
@@ -199,7 +201,12 @@ class SupabaseAuth with WidgetsBindingObserver {
199201
// initial link was done with getInitialAppLink. Being in this catch
200202
// handler means we are in at least version 6.0.0, meaning we do not
201203
// need to handle the initial link manually.
202-
// https://pub.dev/packages/app_links/changelog
204+
//
205+
// app_links claims that the initial link will be included in the
206+
// `uriLinkStream`, but that is not the case for web
207+
if (kIsWeb) {
208+
uri = await (_appLinks as dynamic).getInitialLink();
209+
}
203210
}
204211
if (uri != null) {
205212
await _handleDeeplink(uri);

0 commit comments

Comments
 (0)