@@ -43,9 +43,6 @@ class GoTrueClient {
43
43
/// Namespace for the GoTrue MFA API methods.
44
44
late final GoTrueMFAApi mfa;
45
45
46
- /// The currently logged in user or null.
47
- User ? _currentUser;
48
-
49
46
/// The session object for the currently logged in user or null.
50
47
Session ? _currentSession;
51
48
@@ -140,10 +137,10 @@ class GoTrueClient {
140
137
/// Returns the current logged in user, if any;
141
138
///
142
139
/// 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
144
141
/// when the user signed up using email and password but has not confirmed
145
142
/// their email address.
146
- User ? get currentUser => _currentUser ;
143
+ User ? get currentUser => _currentSession ? .user ;
147
144
148
145
/// Returns the current session, if any;
149
146
Session ? get currentSession => _currentSession;
@@ -748,8 +745,7 @@ class GoTrueClient {
748
745
options: options);
749
746
final userResponse = UserResponse .fromJson (response);
750
747
751
- _currentUser = userResponse.user;
752
- _currentSession = currentSession? .copyWith (user: userResponse.user);
748
+ _currentSession = currentSession! .copyWith (user: userResponse.user);
753
749
notifyAllSubscribers (AuthChangeEvent .userUpdated);
754
750
755
751
return userResponse;
@@ -970,7 +966,6 @@ class GoTrueClient {
970
966
}
971
967
972
968
_currentSession = session;
973
- _currentUser = session.user;
974
969
notifyAllSubscribers (AuthChangeEvent .initialSession);
975
970
}
976
971
@@ -997,7 +992,7 @@ class GoTrueClient {
997
992
}
998
993
} else {
999
994
final shouldEmitEvent = _currentSession == null ||
1000
- _currentSession? .user.id != session.user.id;
995
+ _currentSession! .user.id != session.user.id;
1001
996
_saveSession (session);
1002
997
1003
998
if (shouldEmitEvent) {
@@ -1153,13 +1148,11 @@ class GoTrueClient {
1153
1148
_log.finest ('Saving session: $session ' );
1154
1149
_log.fine ('Saving session' );
1155
1150
_currentSession = session;
1156
- _currentUser = session.user;
1157
1151
}
1158
1152
1159
1153
void _removeSession () {
1160
1154
_log.fine ('Removing session' );
1161
1155
_currentSession = null ;
1162
- _currentUser = null ;
1163
1156
}
1164
1157
1165
1158
void _mayStartBroadcastChannel () {
0 commit comments