Firebase google auth automatically selecting user. How to force it to select account
Asked Answered
P

4

27

If in any browser, when i am logged in with single google account and try to invoke 'sign in with google' option on firebase, it is automatically logging-in to firebase with the already logged in account. It gives me no option to login with a different account. This happens only if one account is logged in browser. Multiple accounts doesn't create this problem. So, it is any way I can force users to choose accounts everytime they click 'sign in with google' button?

Pinhead answered 19/8, 2016 at 6:16 Comment(0)
C
53

This worked for me: https://groups.google.com/forum/#!topic/firebase-talk/gxBm0WKCuIY

var provider = new firebase.auth.GoogleAuthProvider();
provider.setCustomParameters({
  prompt: 'select_account'
});
Co answered 1/5, 2017 at 22:57 Comment(3)
This works only for web. What about cordova. I am using const googleCredential = firebase.auth.GoogleAuthProvider.credential(response.idToken); firebase.auth().signInAndRetrieveDataWithCredential(googleCredential) . How to use here prompt here ?Smashandgrab
For all custom parameters you can take a look here: developers.google.com/identity/protocols/…Camelback
@Smashandgrab maybe take a look here, using a slightly different flow: firebase.google.com/docs/auth/web/…. There you can use the provider.Camelback
H
7

For those initiating a Google Sign In from mobile, when instantiating your sign in object, you can simply use the revokeAccess method to force the account picker to be displayed

googleSignInClient = GoogleSignIn.getClient(this, googleSignInOptions)
googleSignInClient.revokeAccess()
Heder answered 9/9, 2021 at 22:33 Comment(1)
googleSignInClient.signOut() should be enoughWaistcloth
G
1

If you're authenticating the user credential Using Google Sign-In with JavaScript, try to remove the follow line of code:

provider.addScope('https://www.googleapis.com/auth/plus.login');

After you clicked the sign in button, it will allow you to select a Google account that you want to use.

Geddes answered 20/8, 2016 at 14:19 Comment(1)
I tried as you said above. But, nothing changes. I see the account information on the top right even earlier. What i need is, no matter how many accounts are linked to the browser at that instance, it should definitely ask the user to pick / add an account.Pinhead
W
0

when you logs out call this method -

GoogleSignIn().signOut();

This is enough

Wellbeloved answered 6/3 at 5:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.