【问题标题】:getAuth() returns nullgetAuth() 返回 null
【发布时间】:2015-11-07 11:56:02
【问题描述】:

我需要对 facebook、twitter 和 google 使用用户身份验证。我最初创建了一个 firebase 帐户并使用了以下代码。

var ref = new Firebase("https://keks.firebaseio.com");
    ref.getAuth();
    console.log(ref.getAuth());

这总是在我的控制台中返回 null。为什么会发生这种情况?有人可以帮我吗?

【问题讨论】:

    标签: firebase-authentication


    【解决方案1】:

    调用getAuth() 不会对用户进行身份验证,它只会返回当前的身份验证状态。 API documentation 说:

    返回 Firebase 客户端的当前身份验证状态。如果客户端未经身份验证,此方法将返回null

    由于您收到null,这意味着您的用户尚未通过身份验证。您可以通过调用authWithOAuthPopup() 来验证用户身份:

    function authHandler(error, authData) {
      if (error) {
        console.log("Login Failed!", error);
      } else {
        console.log("Authenticated successfully with payload:", authData);
      }
    }
    ref.authWithOAuthPopup("<provider>", authHandler);
    

    最后一个 sn-p 来自Firebase documentation on authentication

    由于我的回答的两个部分都来自 Firebase 文档,我强烈建议您花一些时间在那里。

    【讨论】:

    • authData 是否来自 authWithOAuthPopup() ?@Frank van Puffelen
    • authWithOAuthPopup()传入回调。
    猜你喜欢
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-21
    相关资源
    最近更新 更多