Reputation: 343
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!
Upvotes: 2
Views: 7365
Reputation: 343
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.
Upvotes: 2
Reputation: 11
Change your code from
auth.$createUserWithEmailAndPassword({
email: this.user.email,
password: this.user.password
})
to
auth.createUserWithEmailAndPassword(user.email, user.password);
Upvotes: 1
Reputation: 2026
$scope.register = function() {
firebase.auth().createUserWithEmailAndPassword($scope.email, $scope.password)
.then(function(user) {
console.log(user);
})
.catch(function(error) {
console.log(error);
});
//}
}
here, you can use it this way.
Upvotes: 0
Reputation: 1920
Change the function parameters as follows:
this.register = function() {
auth.$createUserWithEmailAndPassword(this.user.email,this.user.password).then(function(regUser) {
$log.log(regUser);
}).catch(function(error) {
$log.log(error);
});
};
Upvotes: 0