Can't get new password authentication methods to work in AngularFire 0.9.0?

泪湿孤枕 提交于 2019-12-04 16:17:06

The problem you are running into is that the AngularFire API is slightly different than the regular Firebase API for the authentication methods. While the Firebase SDK takes a callback as the second argument for authWithPassword(), the AngularFire API returns a promise for $authWithPassword(). The reason for the difference is that promises are a very common idiom in Angular and we wanted to provide an API that people are already familiar with. So, your code should look like this:

var app = angular.module("sampleApp", ["firebase"]);

app.controller('mainCtrl', function ($scope, $firebaseAuth) {
  var ref = new Firebase('https://XXXX.xxx');

  $scope.auth = $firebaseAuth(ref);

  $scope.login = function() {
    $scope.num = 'logging in';
    $scope.auth.$authWithPassword({
      email: 'xxx@xxx.xxx',
      password: 'yyyyy'
    }).then(function(authData) {
      console.log(authData);
    }).catch(function(error) {
      console.log(err);
      $scope.num = err;
    });
  };
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!