2

When I press the "Logout" in app, the currentUser become null but don't really logout app, I'm using ScopedModel, if I print(model.isLoggedIn()) returns true, it means that exist some user in app, but the user is null.

When I press to signOut, I receive a message on output:

D/FirebaseAuth( 5252): Notifying id token listeners about a sign-out event.
D/FirebaseAuth( 5252): Notifying auth state listeners about a sign-out event.
D/FirebaseAuth( 5252): Notifying id token listeners about a sign-out event.
D/FirebaseAuth( 5252): Notifying auth state listeners about a sign-out event.
I/flutter ( 5252): true ( print in model.isLoggedIn() )

Follows signOut code

  void signOut() async{
    print(isLoggedIn());
    await FirebaseAuth.instance.signOut();
    userData = Map();
    notifyListeners();
    print(isLoggedIn());
  }

  bool isLoggedIn(){ return FirebaseUser != null; }

this is the complete code about UserModel: https://github.com/willsgobi/coleirapet/blob/master/lib/models/loginmodel.dart

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
William Sgobi
  • 95
  • 1
  • 3
  • 6
  • "currentUser become null but don't really logout app" What do you mean that they don't really log out of the app? What does `isLoggedIn` do? – Frank van Puffelen Dec 03 '19 at 19:40
  • "currentUser become null but don't really logout app": When I press the Logout, the currentUser should be false and the isLoggedIn should be returns false, but isLoggedIn returns true after that I call function FirebaseUser.signOut(), it means that the auth has some currentUser – William Sgobi Dec 03 '19 at 20:17
  • Function isLoggedIn verify is FirebaseUser is true or false: ``` bool isLoggedIn(){ return FirebaseUser != null; } ``` – William Sgobi Dec 03 '19 at 20:18
  • Answer below, but please in future questions ensure that the [minimal, complete/standalone code that is needed to reproduce the problem is present in your question itself](http://stackoverflow.com/help/mcve). I'd recommend studying that link, as it's the best way to improve your chances of getting help for code-related questions. – Frank van Puffelen Dec 03 '19 at 21:09

1 Answers1

2

The FirebaseUser variable is a field of the class, which you set yourself when the user signs in. For example like this in the code from your repo:

_auth.createUserWithEmailAndPassword(
    email: userData["email"],
    password: pass
).then((user) async {
      firebaseUser = user.user;

You're not updating this firebaseUser field when the user signs out, so it still points to the previous object. You'll want to force a reload, with something like this:

await FirebaseAuth.instance.signOut();
firebaseUser = await await _auth.currentUser();
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807