我正在尝试使用 Javascript 客户端库进行 Firebase 身份验证,以使用 Google 帐户和弹出窗口登录。但是,当我尝试登录时,会弹出登录窗口,我选择我的 Google 帐户,然后它花了大约 10 秒加载(蓝色进度条移动),然后弹出窗口关闭,在我得到以下错误消息:
code: "auth/popup-closed-by-user"
message: "The popup has been closed by the user before finalizing the operation."
我在 Firebase 网络用户界面的身份验证部分启用了 Google 登录。下面是我正在使用的代码,它几乎是直接从 Firebase 文档中复制的。我没有对项目配置进行任何其他更改。我启动了一个新项目只是为了对此进行测试,并且只运行了 firebase init
,仅启用托管,并在身份验证 Web UI 中启用 Google 登录。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Welcome to Firebase Hosting</title>
<script src="/__/firebase/7.14.6/firebase-app.js"></script>
<script src="/__/firebase/7.14.6/firebase-auth.js"></script>
<script src="/__/firebase/init.js"></script>
</head>
<body>
<button id="signin">sign in</button>
<button id="signout">sign out</button>
<script>
const provider = new firebase.auth.GoogleAuthProvider();
const signinButton = document.querySelector("#signin");
signinButton.addEventListener("click", () =>
firebase
.auth()
.signInWithPopup(provider)
.then(function (result) {
console.log("result", result);
})
.catch(function (error) {
console.error(error);
})
);
const signoutButton = document.querySelector("#signout");
signoutButton.addEventListener("click", () =>
firebase
.auth()
.signOut()
.then(function () {
console.log("signed out");
})
.catch(function (error) {
console.error(error);
})
);
</script>
</body>
</html>
最佳答案
查看本期:https://github.com/firebase/firebase-js-sdk/issues/3188 .
对于某些用户,这是通过将应用域添加到授权域列表来解决的:
Firebase 控制台 -> 身份验证 -> 登录方法 -> 授权域 -> 添加(域)
关于javascript - Firebase 弹出窗口登录弹出窗口被用户关闭错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62116406/