Skip to content

Commit 3487c87

Browse files
committed
fix: make sure duplicate initial session does not happen
1 parent ff26d93 commit 3487c87

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

packages/supabase_flutter/lib/src/supabase_auth.dart

Lines changed: 11 additions & 11 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.
@@ -194,12 +196,10 @@ class SupabaseAuth with WidgetsBindingObserver {
194196
// before app_links 6.0.0
195197
uri = await (_appLinks as dynamic).getInitialAppLink();
196198
} on NoSuchMethodError catch (_) {
197-
// The AppLinks package contains the initial link in the uriLinkStream
198-
// starting from version 6.0.0. Before this version, getting the
199-
// initial link was done with getInitialAppLink. Being in this catch
200-
// handler means we are in at least version 6.0.0, meaning we do not
201-
// need to handle the initial link manually.
199+
// Needed to keep compatible with 5.0.0 and 6.0.0
202200
// https://pub.dev/packages/app_links/changelog
201+
// after app_links 6.0.0
202+
uri = await (_appLinks as dynamic).getInitialUri();
203203
}
204204
if (uri != null) {
205205
await _handleDeeplink(uri);

0 commit comments

Comments
 (0)