FugueWeb
FugueWeb

Reputation: 754

Angular Firebase $createUser function returns error

I'm at an impasse on this. I'm trying to create a user with AngularFire using $firebaseAuth NOT the deprecated FirebaseSimpleLogin, as recommended in the docs. I am certain that the form submits a valid email and password, but I continue to get the following error in the console:

Error: Firebase.createUser failed: First argument must contain the key "email" with type "string"

You can see the code, I use a factory service to handle the $createUser method, which is where the error is occurring because the subsequent console.logs are not firing once the method returns. Please note, I have also tried using the boilerplate code in the docs rather than splitting it between controller and services and have received the same error. Your assistance is greatly appreciated, thanks!

ng-submit="register()" on Form element

$scope.register = function(){ console.log($scope.user); // logs object correctly // Authentication is passed into the controller as a dependency Authentication.register($scope.user) .then(function(){ //This does NOT fire console.log("User created successfully!"); Authentication.login($scope.user);
}) .then(function(authData){ console.log("Logged in as:", authData.uid); }) .catch(function(error) { console.log('error'); $scope.errorMessage = error.toString(); }); };

Authentication factory service

var obj = {
    register: function(user){
        var obj = {email: user.email, password: user.password};
        console.log(obj); // works correctly
        //var auth has the reference to Firebase
        return auth.$createUser(obj);
    }   
};

Upvotes: 2

Views: 2440

Answers (2)

Peter Sandström
Peter Sandström

Reputation: 75

I get the same error. Angularfire 1.1 or later (code at home) (updated with Bower). I'm following the tutorial https://www.firebase.com/docs/web/libraries/angular/guide/user-auth.html and are using the code for Managing users.

The code works with hard coded strings eg. [email protected]. And I aslo found a work around. If I add + '' to the arguments of the object to $Auth.createUser(). I also works. I feels like my posted email/pwsd text as ng-model are not a string?

Upvotes: 0

jwngr
jwngr

Reputation: 4422

UPDATE: Simply upgrade to AngularFire 0.9.1 or later and this problem will be fixed.

UPDATE DETAILS: Using a single credentials parameter (as the original questioner did) is now the suggested way to call this (and the other authentication methods) as of AngularFire 0.9.1. The format described below has been deprecated and will be removed in an upcoming release, so we do no recommend using it.

This is my fault while writing the documentation. I apologize for the completely understandable confusion. I wanted to keep the API somewhat backwards compatible with the previous AngularFire API and decided to have the user management methods take individual arguments, instead of an object of arguments like the regular Firebase SDK takes. However, the docs (and examples) do not accurately reflect this decision. Your code should look like this:

auth.$createUser("[email protected]", "password").then(function() {
  console.log("User created successfully!");
}).catch(function(error) {
  console.log("Error:", error);
});

I'll get the docs updated immediately but here is the answer to get you unblocked.

Upvotes: 7

Related Questions