ref.$authWithPassword is not a function in Firebase

喜你入骨 提交于 2019-12-11 19:45:27

问题


One of these days where one bug follows the other jeezzz... So much for using firebase as an easy data source for my apps. I was just about to start implementing $firebaseSimpleLogin when it broke and I found out though stackoverflow that it was deprecated in favour of $firebaseAuth. However, now I am unable to update the function in the controller because it throws the same error time and time again:

TypeError: ref.$authWithPassword is not a function

I have added all the dependencies to my controller, created the ref object from my firebase source and the thing still won't allow my user (already created) to log i. Here is the code:

controllersModule.controller('HomeCtrl',  ["$scope", "$firebaseAuth",
  function($scope, $firebaseAuth) {
    var ref = new Firebase("https://<MYUSERAPI>.firebaseio.com");
     var auth = $firebaseAuth(ref);

  $scope.user = {};
  $scope.SignIn = function(e){
     e.preventDefault();
     var username = $scope.user.email;
     var password = $scope.user.password;

//AMENDED - Still Getting an error auth.$login('password', { email: username, password: password }) .then(function(user) { //Success callback console.log('Authentication successful'); }, function(error) { //Failure callback console.log('Authentication failure'); }); } }]);

It tells me the at ref.$authWithPassword is not a function? Am I missing a plugin?

I have the following versions of firebase and Angular fire:

          <script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
          <script src="https://cdn.firebase.com/libs/angularfire/1.1.3/angularfire.min.js"></script>

I have gone onto this page https://www.firebase.com/docs/web/guide/login/password.html but cannot recreate their options with my login/password version in angular.

Any help with be much appreciated, today especially. Thanks.


回答1:


I Have fixed by going back to $authWithPassword and adding auth just as per Anid's post and it works.

$scope.user = {};
  $scope.SignIn = function(e){
     e.preventDefault();
     var username = $scope.user.email;
     var password = $scope.user.password;
     auth.$authWithPassword ({
                email: username,
                password: password
            })
            .then(function(user) {
                //Success callback
                console.log('Authentication successful');
            }, function(error) {
                //Failure callback
                console.log('Authentication failure');
            });
  }



回答2:


$authWithPassword is an AngularFire method, not a Firebase reference method. You should call that method on your auth variable.



来源:https://stackoverflow.com/questions/32894504/ref-authwithpassword-is-not-a-function-in-firebase

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