0

Another weird one for today. I am creating a registration form in angularjs, the form sits inside a view folder called register.html. It is retrieved and displayed the ng-view in the homepage.

The controller is also so set in a separate file with various other controllers. The big problem for me is that I am unable to create a register function as angular fire keeps throwing my this error:

 $createUser() expects an object containing 'email' and 'password', but got a string.

This is crazy because in my function both are variables:

//Register controller
controllersModule.controller("RegCtrl", ["$scope",  "$firebaseAuth",
  function($scope, $firebaseAuth){
    var ref = new Firebase("https://<MY APP>.firebaseio.com");
     var auth = $firebaseAuth(ref);



    $scope.signUp = function() {
      if (!$scope.regForm.$invalid) {
       var email = $scope.user.email;
           var password = $scope.user.password;
           if (email && password) {
               auth.$createUser(email, password)
                   .then(function() {
                       // do things if success
                       console.log('User creation success');
                   }, function(error) {
                       // do things if failure
                       console.log(error);
                       console.log('something is not right');
                       $scope.regErrorMessage = error.message;
                   });
                }
             }
          };
}]);
//.End Register controller

The form also specifies the type of data they are:

        <input type="password" name="password" class="form-control" ng-model="user.password" ng-minlength="8">

        <input type="email" name="email" class="form-control" ng-model="user.email">

I really do not understand what this error means and can't think of any more ways to specify email and password. Can someone please help?

HGB
  • 2,157
  • 8
  • 43
  • 74
  • Please look at the code sample here: https://www.firebase.com/docs/web/libraries/angular/guide/user-auth.html#section-managing-users You'll see that `$firebaseAuth.$createUser()` takes an object with two named properies: `email` and `password`. `$firebaseAuth(ref).$createUser({ email: $scope.email, password: $scope.password })` – Frank van Puffelen Oct 02 '15 at 00:27
  • I am on my phone right now but does it mean that I could use ({ email: email, password : password}) as in my variables defined above? – HGB Oct 02 '15 at 06:51
  • I was able to test it now. It worked! auth.$createUser( {email: email, password: password}) thanks! – HGB Oct 02 '15 at 07:48

0 Answers0