Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
113
rated 0 times [  119] [ 6]  / answers: 1 / hits: 57047  / 8 Years ago, wed, november 2, 2016, 12:00:00

According to the JS Auth documentation on the Firebase website, it only shows how to get the displayName and how to update displayName. So I tried to update it. But it is sort of not logical, because how can you update something without creating it.



So my question here is, how can I set displayName of user during registeration?





function createUser(email, password) {
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function (error) {
error.message.replace(., );
alert(error.message + ( + error.code + ));
document.getElementById(password).value = ;
});
if (firebase.auth().currentUser != null) {
firebase.auth().currentUser.updateProfile({
displayName: document.getElementById(name).value
}).then(function () {
console.log(Updated);
}, function (error) {
console.log(Error happened);
});
}
}





I have already tried this and it has been proven not to work...



Sincerely,
Farouk


More From » firebase

 Answers
33

You have to chain the request:



firebase.auth().createUserWithEmailAndPassword(email, password)
.then(function(result) {
return result.user.updateProfile({
displayName: document.getElementById(name).value
})
}).catch(function(error) {
console.log(error);
});`

[#60203] Tuesday, November 1, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anabellejaynav

Total Points: 176
Total Questions: 105
Total Answers: 105

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;