【问题标题】:Firebase SimpleAuth returns null with promiseFirebase SimpleAuth 返回 null 并承诺
【发布时间】:2014-05-06 15:01:53
【问题描述】:

我想创建包含用户 ID 的 firebase 参考。这是我的代码:

var authref = new Firebase('https://myfunnyapp.firebaseio.com');
$scope.auth = $firebaseSimpleLogin(authref);

$scope.auth.$getCurrentUser().then(function(user) {
  var ref = new Firebase('https://myfunnyapp.firebaseio.com/events/' + user.id);
  $scope.events = $firebase(ref);
});

当用户被认证时,我使用 promise 回调来解析用户。

当我已经登录时,这在刷新时正常工作。但是在 auth.$login() 调用后用户等于 null。

【问题讨论】:

  • 您的 $login() 代码在哪里? $login 的承诺中返回了什么,catch/finally 块呢?控制台出现什么错误?
  • $login() 是标准的 auth.$login (auth 从 $firebaseSimpleLogin 返回
  • 您需要详细回答这些问题才能获得帮助;我们需要能够验证和重现问题,以确定您需要采取什么措施来解决它。

标签: angularjs firebase firebase-security


【解决方案1】:

我自己找到了答案。要获得 $login 调用的响应,您必须为其提供回调函数。喜欢:

$scope.login = function() {
  $scope.auth.$login('facebook').then(function(user) {
    console.log(user);
  }, function(error) {
    console.error('Login failed: ', error);
  });
};

【讨论】:

    猜你喜欢
    • 2022-08-18
    • 1970-01-01
    • 2018-09-27
    • 2017-03-11
    • 2016-06-15
    • 2019-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多