0
votes

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.

2

2 Answers

1
votes

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');
            });
  }
0
votes

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