FirebasesignInWithPopup()函数,弹出google登录窗口但弹出窗口不显示任何google帐户

Has*_*nir 5 javascript authentication firebase reactjs firebase-authentication

我正在使用 firebase 进行“Google 登录身份验证”...但是登录弹出窗口没有显示任何可用的 google 用户,并且弹出窗口在大约 5 秒后消失并且不执行任何操作。

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;
Run Code Online (Sandbox Code Playgroud)

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;
Run Code Online (Sandbox Code Playgroud)

SignInWithGoogle 弹出窗口应显示可用的 google 帐户,我从中选择一个帐户并继续,并在 firebase 身份验证用户中注册该用户。但弹出窗口没有显示任何可用的谷歌帐户(我的浏览器中有两个登录帐户),并且弹出窗口在大约5秒后自动消失。

在此输入图像描述

小智 9

如果您希望 FirebasesignInWithGoogle在使用当前身份验证令牌之前停止并询问要登录哪个 google 帐户,您将需要使用该setCustomerParameters方法并手动调用提示,如下所示...

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);
Run Code Online (Sandbox Code Playgroud)

文档链接setCustomerParameters


emc*_*e22 0

您是否尝试过启用该提供程序?对于您的示例,您必须进入 firebase 中的项目,转到“身份验证”选项卡,然后单击“登录方法”并检查是否启用了 Google。