【问题标题】:On Auth State changed AngularFire在 Auth State 上更改了 AngularFire
【发布时间】:2016-10-27 01:47:25
【问题描述】:

尝试使用 firebase 对用户进行身份验证。使用 firebase 2.xx 启动了我的应用程序,但即使在升级到 Firebase 3.xx 之后,仍然抛出 错误“onAuthStateChanged 不是函数”。

这就是我的登录功能的样子-

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

【问题讨论】:

    标签: angularjs firebase angularfire firebase-authentication


    【解决方案1】:

    您的问题是您将$firebaseObject 传递给$firebaseAuth()

    因此,请确保您正在初始化您的 [$firebaseAuth][1] 对象,如下所示,然后您的代码应该可以正常工作。

    var loginObj = $firebaseAuth();
    

    为演示工作jsFiddle

    你可以在这里查看AngularFire2的文档

    【讨论】:

      猜你喜欢
      • 2019-08-08
      • 2014-10-09
      • 2012-02-10
      • 2021-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多