我试图使用角消防0.9.0新的身份验证方法,但我必须做一些错误的。
I'm trying to use the new authentication methods in Angular Fire 0.9.0 but I must be doing something wrong.
我跑的角度1.3.2,火力地堡的2.0.4和角火0.9.0。
I'm running 1.3.2 of Angular, 2.0.4 of Firebase and 0.9.0 of Angular Fire.
我把从 NG-点击
登录功能在我的HTML。
I call the login function from an ng-click
in my html.
下面是我的JS:
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 = 'loggin in';
$scope.auth.$authWithPassword({
email: 'xxx@xxx.xxx',
password: 'yyyyy'
}, function(err, authData) {
if (err) {
console.log(err);
$scope.num = err;
} else {
console.log(authData);
}
});
};
我没有在控制台中看到什么,我没有得到任何错误。所以,我无法弄清楚如何调试我在做什么错。
I don't see anything in the console and I don't get any errors. So I can't figure out how to debug what I am doing wrong.
当我登录 $ scope.auth
到控制台,它显示了 $ authWithPassword
方法。我只是不能得到它的工作。
When I log $scope.auth
to the console, it shows the $authWithPassword
method. I just can't get it to work.
任何帮助将是AP preciated。
Any help would be appreciated.
推荐答案
您正在运行到的问题是,AngularFire API是比对验证方法的常规火力地堡API略有不同。虽然火力地堡SDK需要一个回调为authWithPassword第二个参数(),该API AngularFire返回$ authWithPassword承诺()。究其原因,不同的是,承诺在角很常见的成语,我们希望提供一个API,人们已经非常熟悉。所以,你的code应该是这样的:
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;
});
};
});
相关推荐
最新文章