Reputation: 55
since I just learning flutter and I kinda follow old videos so most of the code for firebase were deprecated.
would like to know if there's any link to it for revisions
firebaseAuth.currentUser.then((user){
if(user != null){
setState(() => isLoggedIn = true);
}
});
Upvotes: 1
Views: 582
Reputation: 1978
Try This
FirebaseAuth.instance.authStateChanges().listen((User user) {
if (user == null) {
print('User is currently signed out!');
} else {
print('User is signed in!');
}
});
https://firebase.flutter.dev/docs/auth/usage/#authentication-state
Upvotes: 0
Reputation: 18690
Getting currentUser
actually got easier. Now it's not a future, so you don't have to await
or use then
. You can get the user like this:
final user = firebaseAuth.currentUser;
if(user != null){
setState(() => isLoggedIn = true);
}
Upvotes: 3