Skip to content

refactor(gotrue): Remove unused _currentUser field and update currentUser getter logic. #1168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

juampiq6
Copy link

@juampiq6 juampiq6 commented May 7, 2025

What kind of change does this PR introduce?

Refactor

What is the current behavior?

_currentUser variable is just being stored as a copy of _currentSession.user

What is the new behavior?

The currentUser getter is handling the indirection correctly, no need to duplicate values and assign both each time they change.

Additional context

I have simplified a comment (it was a double negation).
I have added some bang operators in cases where null-aware operator where not needed

…User getter logic. Simplified comments and fixed some nullcheck operators
@@ -997,7 +992,7 @@ class GoTrueClient {
}
} else {
final shouldEmitEvent = _currentSession == null ||
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if current session is null, then the second bang operator in the expression will never reach

@@ -748,8 +745,7 @@ class GoTrueClient {
options: options);
final userResponse = UserResponse.fromJson(response);

_currentUser = userResponse.user;
_currentSession = currentSession?.copyWith(user: userResponse.user);
_currentSession = currentSession!.copyWith(user: userResponse.user);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if access token is null, then the code will never reach the bang operator, hence it should be safe to use it here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant