Firebase 弹出登录弹出窗口被用户关闭错误

问题描述 投票:0回答:4

我正在尝试使用 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 Web UI 的身份验证部分启用 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>
javascript firebase firebase-authentication google-signin
4个回答
2
投票

请参阅此问题:https://github.com/firebase/firebase-js-sdk/issues/3188

对于某些用户,可以通过将应用程序域添加到授权域列表来解决此问题:
Firebase 控制台 -> 身份验证 -> 登录方法 -> 授权域 -> 添加(域)


2
投票

对于某些用户来说,这可能是由

Firefox Containers
功能或 Firefox
Enhanced Tracking Protection
功能(特别是其
isolate other cross-site cookies
功能)引起的。


0
投票

此外,发生这种情况可能是因为您没有发现错误。捕获错误将有助于避免网站崩溃。

  signInWithPopup(auth, provider)
  .then((result) => {
    console.log("Logged In", result);
  })
  .catch((error) => {
    console.log("Caught error Popup closed");
  });

0
投票

我知道有点晚了。这为我解决了问题:

  async loginWithFacebook() {
    const provider = new FacebookAuthProvider();
    provider.setCustomParameters({ display: 'popup' });
    const userCredentials = await this.afAuth
      .signInWithPopup(provider);
    // some other code
}

添加自定义参数就可以了。

© www.soinside.com 2019 - 2024. All rights reserved.