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