简体   繁体   中英

Firebase signInWithPopup() function, pop-up google sign in Window but the pop-up does not show any google accounts

I am doing "Google Sign In Authentication" using firebase... but the sign-in pop-up window does not show any available google users, and the pop-up window disappears after about 5 sec and does not do anything.

Code in firebase.js :

import firebase from "firebase/app";
import "firebase/firestore";
import "firebase/auth";

var firebaseConfig = {
  apiKey: "AIzaSyDSxAzARyErU6gr7ujsEfg2hB6DYz02OnA",
  authDomain: "crwn-db-3c771.firebaseapp.com",
  databaseURL: "https://crwn-db-3c771.firebaseio.com",
  projectId: "crwn-db-3c771",
  storageBucket: "",
  messagingSenderId: "395022734699",
  appId: "1:395022734699:web:39122ca48383548f"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);

export const auth = firebase.auth();
export const firestore = firebase.firestore();

const provider = new firebase.auth.GoogleAuthProvider();
provider.setCustomParameters({ prompt: "select_account" });
export const signInWithGoogle = () => auth.signInWithPopup(provider);

export default firebase;

Code in sign-in.jsx :

import { signInWithGoogle } from "../../firebase/firebase.utils";


class SignIn extends React.Component {
  render() {
    return (
          <CustomButton onClick={signInWithGoogle}>
            Sign in with Google
          </CustomButton>
      </div>
    );
  }
}

export default SignIn;

The signInWithGoogle pop-up window should show available google accounts, from which I select one and it continues, and register that user in firebase authentication user. But the pop-up does not show any available google account (there are two logged in accounts in my browser), and the pop-up disappears automatically after about 5 sec.

enter image description here

I had same issue, i rebooted my mac and it worked perfectly. if that error still exists, try this:

instead of this

export const signInWithGoogle = () => auth.signInWithPopup(provider); 

use this:

export const signInWithGoogle = () => auth.signInWithRedirect(provider);

Have you tried to enable the provider? For your example you have to go into your project in firebase, go to Authentication tab, then click on Sign-In Method and check if Google is enabled.

It sounds like normal the behavior for the case where the user actually got signed in automatically using the Google account that was also signed into Chrome. Add an auth state listener and add some logs that check to see if the user is actually signed in at that point.

I also faced same problem. I enabled 3rd party cookies on my chrome and It worked So Please try this also.

If you want Firebase signInWithGoogle to stop and ask which google account to sign in to before using the current auth token you will need to use the setCustomerParameters method and manually invoke the prompt like so...

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

//works for signInWithPopup and signInWithRedirect

const signInWithPopup = () => auth.signInWithPopup(provider);  
const signInWithRedirect = () => auth.signInWithRedirect(provider);

Link to setCustomerParameters documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM