From 2c2056f8b173ae3afe003a2b1c7d384fc72dd460 Mon Sep 17 00:00:00 2001 From: dshukertjr Date: Mon, 22 Jan 2024 11:21:57 +0900 Subject: [PATCH 1/2] fix(gotrue): Set _currentUser when setting initial session --- packages/gotrue/lib/src/gotrue_client.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/gotrue/lib/src/gotrue_client.dart b/packages/gotrue/lib/src/gotrue_client.dart index 4fd9ce24..03ac31c6 100644 --- a/packages/gotrue/lib/src/gotrue_client.dart +++ b/packages/gotrue/lib/src/gotrue_client.dart @@ -901,6 +901,7 @@ class GoTrueClient { } _currentSession = session; + _currentUser = _currentSession?.user; notifyAllSubscribers(AuthChangeEvent.initialSession); } From 752bea3a736ff69fbced2bcf975665b57eb526a7 Mon Sep 17 00:00:00 2001 From: dshukertjr Date: Mon, 22 Jan 2024 18:13:52 +0900 Subject: [PATCH 2/2] Add comment to currentUser to direct people to use currentSession to see if session exists --- packages/gotrue/lib/src/gotrue_client.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/gotrue/lib/src/gotrue_client.dart b/packages/gotrue/lib/src/gotrue_client.dart index 03ac31c6..b315033c 100644 --- a/packages/gotrue/lib/src/gotrue_client.dart +++ b/packages/gotrue/lib/src/gotrue_client.dart @@ -120,6 +120,11 @@ class GoTrueClient { Map get headers => _headers; /// Returns the current logged in user, if any; + /// + /// Use [currentSession] to determine whether the user has an active session, + /// because [currentUser] can be non-null without an active session, such as + /// when the user signed up using email and password but has not confirmed + /// their email address. User? get currentUser => _currentUser; /// Returns the current session, if any; @@ -901,7 +906,7 @@ class GoTrueClient { } _currentSession = session; - _currentUser = _currentSession?.user; + _currentUser = session.user; notifyAllSubscribers(AuthChangeEvent.initialSession); }