Skip to content

Commit 88ed5d8

Browse files
authored
refactor(gotrue): Remove unused _currentUser field and update currentUser documentation. (#1168)
* refactor(gotrue): Remove unused _currentUser field and update currentUser getter logic. Simplified comments and fixed some nullcheck operators * fix: rolled back to null aware op when checking currentSession. docs: kept the currentUser comments simple
1 parent 369dcc2 commit 88ed5d8

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

packages/gotrue/lib/src/gotrue_client.dart

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -137,13 +134,8 @@ class GoTrueClient {
137134
/// Getter for the headers
138135
Map<String, String> get headers => _headers;
139136

140-
/// Returns the current logged in user, if any;
141-
///
142-
/// Use [currentSession] to determine whether the user has an active session,
143-
/// because [currentUser] can be non-null without an active session, such as
144-
/// when the user signed up using email and password but has not confirmed
145-
/// their email address.
146-
User? get currentUser => _currentUser;
137+
/// Returns the current logged in user, asociated to [currentSession] if any;
138+
User? get currentUser => _currentSession?.user;
147139

148140
/// Returns the current session, if any;
149141
Session? get currentSession => _currentSession;
@@ -748,7 +740,6 @@ class GoTrueClient {
748740
options: options);
749741
final userResponse = UserResponse.fromJson(response);
750742

751-
_currentUser = userResponse.user;
752743
_currentSession = currentSession?.copyWith(user: userResponse.user);
753744
notifyAllSubscribers(AuthChangeEvent.userUpdated);
754745

@@ -970,7 +961,6 @@ class GoTrueClient {
970961
}
971962

972963
_currentSession = session;
973-
_currentUser = session.user;
974964
notifyAllSubscribers(AuthChangeEvent.initialSession);
975965
}
976966

@@ -997,7 +987,7 @@ class GoTrueClient {
997987
}
998988
} else {
999989
final shouldEmitEvent = _currentSession == null ||
1000-
_currentSession?.user.id != session.user.id;
990+
_currentSession!.user.id != session.user.id;
1001991
_saveSession(session);
1002992

1003993
if (shouldEmitEvent) {
@@ -1153,13 +1143,11 @@ class GoTrueClient {
11531143
_log.finest('Saving session: $session');
11541144
_log.fine('Saving session');
11551145
_currentSession = session;
1156-
_currentUser = session.user;
11571146
}
11581147

11591148
void _removeSession() {
11601149
_log.fine('Removing session');
11611150
_currentSession = null;
1162-
_currentUser = null;
11631151
}
11641152

11651153
void _mayStartBroadcastChannel() {

0 commit comments

Comments
 (0)