On Auth State changed AngularFire

a 夏天 提交于 2019-12-11 05:08:27

问题


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);
        });
}
}]);

回答1:


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



来源:https://stackoverflow.com/questions/38013419/on-auth-state-changed-angularfire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!