I cannot update user name where user is sign in to website it doesnt addit to user account, on displaName it shows null.The user account is created succefully but without user name as i said
const onSubmit = async ({ name, email, password }) => {
setIsLoading(true);
try {
await signup(email, password);
await updateProfile(currentUser, {
displayName: name,
});
setInterval(() => {
<Redirect to="/" />;
}, 5000);
} catch (error) {
setIsLoading(false);
console.log(error);
}
};
You can use .then().
firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then(() => {
// do whatever in here
setUserInfo()
sendEmailVerification()
setDisplayName()
alert('Account created!')
})
.catch(error => {
console.log(error)
alert(error.message)
})
Inside the setDisplayName(), you can set the displayName. In my case, I am using the firstName and lastName, which I am getting through my form.
const setDisplayName = () => {
firebase
.auth()
.currentUser
.updateProfile({
displayName: firstName + ' ' + lastName
})
.then(() => {
console.log('display name set')
})
.catch(error => {
console.log(error)
alert(error.message)
})
}