Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoogleAuthProvider - Option to choose account [duplicate]

I'm working on a project in Flutter. I use this code:

_googleAuthProvider.setCustomParameters({'prompt': 'select_account'});

    UserCredential userCredential;

    if (kIsWeb) {
      userCredential = await _firebaseAuth.signInWithPopup(_googleAuthProvider);
    } else {
      userCredential =
          await _firebaseAuth.signInWithProvider(_googleAuthProvider);
    }

On web I can choose which account I want to log in with. On mobile (iOS & Android) I don't get this choice and automatically log in with the previous logged in user.

How can I ensure that I can choose which account I log in with on mobile as well?

I tried several things including changing the customParameters.

like image 398
FabioDev Avatar asked Feb 02 '26 11:02

FabioDev


1 Answers

  final GoogleSignIn googleSignIn = GoogleSignIn();

  googleSignIn.disconnect();

  final GoogleSignInAccount? googleSignInAccount =
      await googleSignIn.signIn();

  if (googleSignInAccount != null) {
    final GoogleSignInAuthentication googleSignInAuthentication =
        await googleSignInAccount.authentication;

    final AuthCredential credential = GoogleAuthProvider.credential(
        accessToken: googleSignInAuthentication.accessToken,
        idToken: googleSignInAuthentication.idToken);

    userCredential = await _firebaseAuth.signInWithCredential(credential);
  }

This worked for me.

like image 187
FabioDev Avatar answered Feb 05 '26 01:02

FabioDev



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!