在验证状态改变了AngularFire [英] On Auth State changed AngularFire
本文介绍了在验证状态改变了AngularFire的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误onAuthStateChanged不是一个函数。
这是如何我的登录功能看起来像 -
.controller('HomeCtrl',['$ scope','$ location','CommonProp ','$ firebaseAuth','$ firebaseObject',函数($ scope,$ location,CommonProp,$ firebaseAuth,$ firebaseObject){
var firebaseObj = $ firebaseObject(rootRef);
var loginObj = $ firebaseAuth(firebaseObj);
$ b $ scope.SignIn = function($ scope,user){
event.preventDefault(); //防止表单刷新
var username = user.email;
var password = user.password;
$ b loginObj。$ signInWithEmailAndPassword({
email:username,
password: (函数(用户){
//成功回调
console.log('验证成功');
$ location.path(/ welcome);
CommonProp.setUser(user.password.email);
},函数(错误){
//失败回调
console.log(error);
});
}
}]);
解决方案
你的问题是你正在传递一个到
$ firebaseAuth()
。
[$ firebaseAuth] [1]
对象,如下所示,然后您的代码应该正常工作。 <$ p信亦信息范范内范读范范中信息
Trying to authenticate an user using firebase. Started my app using firebase 2.xx but even after upgrading to Firebase 3.xx, throwing error "onAuthStateChanged is not a function".
This is how my login function looks like-
.controller('HomeCtrl', ['$scope','$location','CommonProp','$firebaseAuth', '$firebaseObject',function($scope,$location,CommonProp,$firebaseAuth,$firebaseObject) {
var firebaseObj = $firebaseObject(rootRef);
var loginObj = $firebaseAuth(firebaseObj);
$scope.SignIn = function($scope, user) {
event.preventDefault(); // To prevent form refresh
var username = user.email;
var password = user.password;
loginObj.$signInWithEmailAndPassword({
email: username,
password: password
})
.then(function(user) {
// Success callback
console.log('Authentication successful');
$location.path("/welcome");
CommonProp.setUser(user.password.email);
}, function(error) {
// Failure callback
console.log(error);
});
}
}]);
解决方案
Your problem is that you are passing a $firebaseObject
to $firebaseAuth()
.
So make sure you are initializing your [$firebaseAuth][1]
object like the following and then your code should work properly.
var loginObj = $firebaseAuth();
Working jsFiddle for demonstrating.
You can check here the documentation for AngularFire2
这篇关于在验证状态改变了AngularFire的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文