Cannot sign-out from Facebook using flutter with firebase

3,308

Firebase saves the FirebaseUser object in cache so the user won't need to re-signin every time he leaves the app. So the signOut function should look like this:

Future<void> signOut() async {
    await _facebookLogin.logOut();
    await _auth.signOut();
    _user = null;
  }

And the FirebaseUser user; should be moved out of the signInWithFacebook function (I renamed it to _user).

Share:
3,308
user2570135
Author by

user2570135

Updated on December 11, 2022

Comments

  • user2570135
    user2570135 over 1 year

    I have a flutter app where I am authenticating with Facebook and firebase on iOS. However, I cannot get the login in page again although I am calling the logout function

    I always get the facebook confirmation screen which has some text that inform me that I have already logged in.

    How do I logout so that the next time I am ask to enter my email/pass

    here is a snippet of my code

    Future<FirebaseUser> signInWithFacebook();
    final FirebaseAuth _auth = FirebaseAuth.instance;
    
    Future<FirebaseUser> signInWithFacebook() async {
        FirebaseUser user;
        var result = await _facebookLogin
            .logInWithReadPermissions(['email', 'public_profile']);
        if (result.status == FacebookLoginStatus.loggedIn) {
          FacebookAccessToken myToken = result.accessToken;
          AuthCredential credential =
              FacebookAuthProvider.getCredential(accessToken: myToken.token);
          user = await _auth.signInWithCredential(credential);
        }
        return user;
      }
    
    
    Future<void> signOut() async {
        await _facebookLogin.logOut();
        await _auth.signOut();
      }
    

    Thanks for your help