@@ -43,9 +43,6 @@ class GoTrueClient {
4343 /// Namespace for the GoTrue MFA API methods.
4444 late final GoTrueMFAApi mfa;
4545
46- /// The currently logged in user or null.
47- User ? _currentUser;
48-
4946 /// The session object for the currently logged in user or null.
5047 Session ? _currentSession;
5148
@@ -140,10 +137,10 @@ class GoTrueClient {
140137 /// Returns the current logged in user, if any;
141138 ///
142139 /// Use [currentSession] to determine whether the user has an active session,
143- /// because [currentUser] can be non- null without an active session, such as
140+ /// because [currentUser] can be null with an active session, such as
144141 /// when the user signed up using email and password but has not confirmed
145142 /// their email address.
146- User ? get currentUser => _currentUser ;
143+ User ? get currentUser => _currentSession ? .user ;
147144
148145 /// Returns the current session, if any;
149146 Session ? get currentSession => _currentSession;
@@ -748,8 +745,7 @@ class GoTrueClient {
748745 options: options);
749746 final userResponse = UserResponse .fromJson (response);
750747
751- _currentUser = userResponse.user;
752- _currentSession = currentSession? .copyWith (user: userResponse.user);
748+ _currentSession = currentSession! .copyWith (user: userResponse.user);
753749 notifyAllSubscribers (AuthChangeEvent .userUpdated);
754750
755751 return userResponse;
@@ -970,7 +966,6 @@ class GoTrueClient {
970966 }
971967
972968 _currentSession = session;
973- _currentUser = session.user;
974969 notifyAllSubscribers (AuthChangeEvent .initialSession);
975970 }
976971
@@ -997,7 +992,7 @@ class GoTrueClient {
997992 }
998993 } else {
999994 final shouldEmitEvent = _currentSession == null ||
1000- _currentSession? .user.id != session.user.id;
995+ _currentSession! .user.id != session.user.id;
1001996 _saveSession (session);
1002997
1003998 if (shouldEmitEvent) {
@@ -1153,13 +1148,11 @@ class GoTrueClient {
11531148 _log.finest ('Saving session: $session ' );
11541149 _log.fine ('Saving session' );
11551150 _currentSession = session;
1156- _currentUser = session.user;
11571151 }
11581152
11591153 void _removeSession () {
11601154 _log.fine ('Removing session' );
11611155 _currentSession = null ;
1162- _currentUser = null ;
11631156 }
11641157
11651158 void _mayStartBroadcastChannel () {
0 commit comments