Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot sign-out from Facebook using flutter with firebase

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

like image 882
user2570135 Avatar asked Feb 01 '26 13:02

user2570135


1 Answers

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).

like image 162
Zvi Karp Avatar answered Feb 04 '26 04:02

Zvi Karp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!