Flutter Firebase Auth Facebook Login change account / require username and password again

Viewed 560

I am using Firebase to implement social logins in our application. I have a weird problem with Facebook login where it seems like it is impossibile to change the account. Let me explain:

  1. User clicks on Login with Facebook button
  2. Web view or browser opens up
  3. User logs in with its credentials
  4. Everything works and user can use our app
  5. User logs out within the app
  6. User wants to log in to facebook with a different account, and clicks on login with facebook button
  7. At this time, there's no way to change facebook account. The webview doesn't let you.

I tried to clean the app cache, deleting the app, didn't work. On Android, I need to clear the Browser cache, or logout from Facebook from the browser, and then I can Login with FB correctly with a new account. On iOS, even deleting the Safari cache and everything won't work.

The social login has been implemented following the official documentation, and it's like this:

  Future<UserCredential?> signInWithFacebook() async {

    try {
      if ( await FacebookAuth.instance.accessToken != null )
        await logoutFacebook();
      // Trigger the sign-in flow
      LoginResult loginResult;
      loginResult = await FacebookAuth.instance.login(
        permissions: ['email', 'public_profile'],
        loginBehavior: LoginBehavior.webOnly,
      );
      if (loginResult.status == LoginStatus.success) {
        final AccessToken accessToken = loginResult.accessToken!;
        final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(accessToken.token);
        return await FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
      } else
        throw loginResult.status.toString() + "\n" + loginResult.message.toString();

    } catch (e) {
      LoggerService().error("FACEBOOK LOGIN ERROR", e.toString());
      FacebookAuth.instance.logOut();
      return null;
    }
  }

At the moment I am limited with Flutter 1.22.6 and so I can only use these firebase packages:

  firebase_messaging: ^10.0.7
  flutter_local_notifications: ^8.2.0
  firebase_crashlytics: ^2.2.1
  firebase_core: ^1.6.0
  firebase_auth: ^3.1.1
  flutter_facebook_auth: ^3.5.2

Do you have any idea on how to solve this problem?

Best regards

EDIT: refactored everything to Flutter 2, but I still have the same issue.

1 Answers
Related