【问题标题】:Why does my firebase Google Auth popup close immediately?为什么我的 Firebase Google Auth 弹出窗口会立即关闭?
【发布时间】:2019-08-10 12:32:52
【问题描述】:

我正在关注 this tutorial 来学习 firebase。我克隆了the repo。在第 7 步,我按照它所说的做了(尽管实际上,这里没有什么可做的,因为这些步骤已经在 repo 中完成了)。当我单击 UI 中的 [SIGN-IN WITH GOOGLE] 按钮时,身份验证窗口会弹出并立即关闭。

我正在 VMWare 中的 Ubuntu 客户机中进行开发。在 Firebase 控制台中为该应用授权了以下域:

  • 本地主机
  • blahblah.firebaseapp.com
  • 127.0.0.1

firebase 网站说在这里询问。我首先searched thouroughly,(少数)其他发布的解决方案不起作用。

谁能告诉我为什么会这样?

【问题讨论】:

  • 任何控制台错误或日志?
  • @Bognar 不。最后我只是决定使用他们的一个竞争对手(主要是因为这个问题——我无法走得更远)。

标签: firebase firebase-authentication google-authentication


【解决方案1】:

同样的事情也发生在我身上。 AlexZ005 提供的调试代码帮助我解决了我的问题。

问题是我的浏览器中不允许使用 3rd 方 cookie。我允许了他们,现在它可以工作了。

【讨论】:

    【解决方案2】:

    很抱歉回复晚了,即使您决定进一步使用其他服务提供商,以下内容可能对遇到相同问题的其他人有所帮助。

    弹出窗口可能会在打开后立即关闭,因为您可以使用此处的步骤 5 捕获该错误:https://firebase.google.com/docs/auth/web/google-signin

    这里简单介绍一下sn-p怎么做,修改public/scripts/main.js中的signInWithPopup函数即可:

    firebase.auth().signInWithPopup(provider).then(function(result) {
      // code which runs on success
    }).catch(function(error) {
      // Handle Errors here.
      var errorCode = error.code;
      console.log(errorCode);
      alert(errorCode);
    
      var errorMessage = error.message;
      console.log(errorMessage);
      alert(errorMessage);
    });
    

    根据我的经验,errorCode 可能类似于“auth/unauthorized-domain”,而 errorMessage 可能指向您正在访问的受限域: “此域 (127.0.0.1) 无权运行此操作。将其添加到 Firebase 控制台中的 OAuth 重定向域列表 -> Auth 部分 -> 登录方法选项卡。”

    我的解决方案是使用 localhost:8080 而不是 127.0.0.1:8080,但是也可以使用 errorMessage 中的说明将 127.0.0.1 添加到受信任的域。

    您的错误可能有所不同,但希望它有助于调试。谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-23
      • 1970-01-01
      • 2021-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多