【问题标题】:Firebase facebook popup returns null onAuthFirebase facebook 弹出窗口返回 null onAuth
【发布时间】:2016-04-11 02:35:01
【问题描述】:

我在 ionic 上的 firebase facebook 弹出式登录正常工作,但突然停止工作(好吧,我正在修改应用程序,但我没有触及服务)。该过程仍然可以在浏览器上运行(当我使用 ionic serve 时),但不能在 ionic 应用程序上运行。

var auth = $fAuth(ref);
  // login with Facebook
  auth.$onAuth(function(authData){ // authData -> null
    console.log("Auth..", authData);  // Auth.. null  
    /* refresh user data on firebase and registering push */
  });
  auth.$authWithOAuthPopup("facebook").catch(function(error) {
    console.log("Authentication failed:", error);
  });

当它工作时,$onAuth cb 函数在 authData 变量中接收一个具有 uid 和 facebook 等属性的对象。

当我跑步时:

ref.authWithOAuthPopup("facebook",function(){console.log(arguments)})

或:

ref.authWithOAuthPopup("twitter",function(){console.log(arguments)})

回调函数永远不会触发。

我在 $ionicPlatform.ready 事件上运行身份验证过程。 我已经卸载并重新安装了应用程序,并清理了应用程序数据。

谢谢!

【问题讨论】:

    标签: android popup ionic firebase firebase-authentication


    【解决方案1】:

    你确定它不会触发吗?

    身份验证完成时将调用的回调函数。失败时,第一个参数将是一个指示失败的 Error 对象,带有机器可读的代码属性。 成功时,第一个参数将为 null,第二个参数为包含字段 uid(唯一用户 ID)、provider(标识提供者的字符串)、auth(身份验证令牌有效负载)和 expires (自 Unix 纪元以来的过期时间(以秒为单位) - 以及更多,取决于用于身份验证的提供程序。

    你没有把论据放在那里。 如果你再试一次,我认为它应该可以工作。 来自 firebase 的示例代码:

    ref.authWithOAuthPopup("facebook", function(error, authData) {
    //                                          ^^^^^  ^^^^^^^^
      if (error) {
        console.log("Login Failed!", error);
      } else {
        console.log("Authenticated successfully with payload:", authData);
      }
    });
    

    【讨论】:

    • 哦,只是为了简短起见,“参数”是在调用函数时传递给函数的所有参数的数组,我也尝试了你建议的代码,但它没有触发:/
    • 正如我所说,authWithOAuthPopuo 的回调甚至不会触发。我在 onAuth 的回调中收到 null。 ref.onAuth(function(data){ /* 这里数据为空 */});
    • 函数的第一个参数是错误对象。 second 是实际数据。如果第一个参数为null,则表示成功(/没有错误)。 ref.onAuth(function(error, data){ /* error will be null, data should be the auth-object */});
    • 嗯,我试过了,我收到错误 -> 空和数据 -> 未定义。我检查了firebase docs,onAuth回调只传递一个参数(这里是链接:firebase.com/docs/web/api/firebase/onauth.html
    • 哦,对不起,我的意思是authWithOAuthPopup,而不是onAuth()。 here's the link
    猜你喜欢
    • 2020-04-18
    • 1970-01-01
    • 2017-08-04
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 2013-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多