Search code examples
angularfirebasefirebase-authenticationangularfiregoogle-authentication

allow user to choose which email to signup with when using angular firebase signup with google


I implemented Angular with Firebase sign up with Google.

var result = await this.afAuth.auth.signInWithPopup(
      new auth.GoogleAuthProvider()
);

When I use Google Chrome, and I am logged in to more than 1 of my Gmail accounts, when I visit my website and I click on Sign Up with Google button, it opens the Google Popup page so I choose which email I want to sign up with to my website. No problem with that.

Google Popup page

But, if I am logged in to only 1 Gmail account on Google Chrome, when I visit my website and I click on Sign Up with Google button, it does not open the Google Popup page, instead it directly makes the sign up with the email that is already logged in on Google Chrome. By default, Google Chrome considers that since this is the only logged in email, let's make him sign up with this email.

What I want is that, at any time a user clicks on my website Sign up with Google button, to open the Google Popup page and let them choose with which email he/she wants to sign up to my website.


Solution

  • We can do this by adding the following custom parameter to the provider:

    const provider = new firebase.auth.GoogleAuthProvider();
    provider.setCustomParameters({ prompt: 'select_account' });
    

    Here is a good explanation: Firebase - What this means to set custom parameters to provider?