Google login popup automatically selects which user to log me in

Viewed 112

I am using firebase google nuxt library to be able to login via Google.

Settings in nuxt.config.js

  firebase: {
    config: {
      apiKey: 'XXXXXXXX',
      authDomain: 'XXXXXXXX',
      databaseURL: 'XXXXXXXX',
      projectId: 'XXXXXXXX',
      storageBucket: 'XXXXXXXX',
      messagingSenderId: 'XXXXXXXX',
      appId: 'XXXXXXXX',
    },
    services: {
      auth: {
        persistence: 'local',
        initialize: {
          onAuthStateChangedMutation: 'XXXXXXXX',,
          onAuthStateChangedAction: 'XXXXXXXX',
          subscribeManually: false,
        },
        ssr: false, // default
        emulatorPort: 'XXXXXXXX',
        emulatorHost: 'XXXXXXXX',
      },
      google: {
        clientId: 'XXXXXXXX',
      },
    },
  },

Usage

  signInWithGooglePopup: function ({ dispatch }) {
    const provider = new this.$fireModule.auth.GoogleAuthProvider();

    const auth = this.$fire.auth

    return Promise.resolve()
      .then(() => auth.signInWithPopup(provider))
  }

I manage to log in to the system, but the problem arises that if one email is saved in Google, then the Google login window (login popup) does not offer to choose whether I want to log in with the existing saved email or add a new one. Google login window (popup) automatically logs me in with a known email for them. This is not a good behavior for my application.

I tried to do an additional logout every time I call the Google login window (popup), but the problem is not solved.

An example of what I tried

  signInWithGooglePopup: function ({ dispatch }) {
    const provider = new this.$fireModule.auth.GoogleAuthProvider();

    const auth = this.$fire.auth

    return Promise.resolve()
      .then(() => auth.signOut())
      .then(() => auth.signInWithPopup(provider))
  }

enter image description here

Help me figure out how to make Google login window (popup) suggest which user I want to log into the system, and not decide for me.

1 Answers

Solution is add custom parameters to GoogleAuthProvider:

const provider = new this.$fireModule.auth.GoogleAuthProvider();
provider.setCustomParameters({ prompt: 'select_account' });
Related