Reputation: 1401
I want to create an new user in my firebase. This is the code I´m using:
function createUser(email, password, username) {
ref.createUser({
email: email,
password: password
}, function(error) {
if (error === null) {
$activityIndicator.stopAnimating();
$scope.padding_error = null;
$scope.error = null;
logUserIn(email, password);
} else {
$activityIndicator.stopAnimating();
console.log(error.code);
switch (error.code) {
case "INVALID_EMAIL":
$scope.padding_error = "10";
$scope.error = "Falsche E-Mail Adresse oder falsches Passwort";
$scope.$apply();
case "INVALID_PASSWORD":
$scope.padding_error = "10";
$scope.error = "Falsche E-Mail Adresse oder falsches Passwort";
$scope.$apply();
case "EMAIL_TAKEN":
$scope.padding_error = "10";
$scope.error = "Diese E-Mail Adresse ist schon registriert";
$scope.$apply();
}
}
});
}
I want to store the username in addition to email and password somewhere in my firebase. How is this possible instantly after user registration?
Upvotes: 0
Views: 152
Reputation: 56
If the registration is succesful you can simply push the email and password variables to firebase. See code below.
function createUser(email, password, username) {
ref.createUser({
email: email,
password: password
}, function(error) {
if (error === null) {
... Registration successful
$activityIndicator.stopAnimating();
$scope.padding_error = null;
$scope.error = null;
##NEWCODE HERE##
emailRef = new Firebase("<YOURFIREBASEURL>/accounts/"+username+"/email")
passRef = new Firebase("<YOURFIREBASEURL>/accounts/"+username+"/password")
emailRef.set(email)
passRef.set(password)
logUserIn(email, password);
} else {
... Something went wrong at registration
}
}
});
}
Upvotes: 1