Search code examples
angularjsfirebasefirebase-authenticationangularfire

Firebase auth.$createUserWithEmailAndPassword not working


I have been following a course on Firebase, but quickly discovered a lot of things have changed. https://www.firebase.com/docs/web/libraries/angular/api.html#angularfire-users-and-authentication-createusercredentials these docs are completely outdated.

Here I declare my firebase variables

var ref = firebase.database().ref();
var firebasedata = $firebaseObject(ref);
var auth = $firebaseAuth();

Then I try to call this function

this.register = function() {
  auth.$createUserWithEmailAndPassword({
    email: this.user.email, 
    password: this.user.password
  }).then(function(regUser) {
    $log.log(regUser);
  }).catch(function(error) {
    $log.log(error);
  });
};

But it throws this error:

code : "auth/argument-error" message : "createUserWithEmailAndPassword failed: First argument "email" must be a valid string."

I have searched for answers to this problem but all I can find is updating my angularfire or firebase (which are both the latest version) or that this.user.email is not a string. When I do a

 console.log(this.user.email);

I can see it is a string containing a valid e-mail.

Any help into the right direction would be welcome!


Solution

  • For anyone experiencing this issue:

    the old

    auth.$createUser()

    function took an user-object as parameter.

    While:

    auth.$createUserWithEmailAndPassword()

    takes 2 strings as parameters, not an object.