I was using firebase authentication createUserWithEmailAndPassword to create a user and used the updateProfile method to update the displayName of the user. Below is my code.
const signUp = (event) => {
event.preventDefault();
console.log(username);
auth.createUserWithEmailAndPassword(email,password)
.then((authUser)=>{
authUser.user.updateProfile({
displayName : username
})
})
.catch(err=>alert(err.message));
}
The signUp function get triggered upon the user clicking the signUp button. The username display correctly in the console.
After creating user, there is another useEffect hook to log the authUser to console
useEffect(()=>{
const unsubscribe = auth.onAuthStateChanged((authUser)=>{
if(authUser){
//user has login...
console.log(authUser);
setUser(authUser);
if(authUser.displayName){
//dont update username
}else{
return authUser.updateProfile({
displayName : username,
})
}
}else{
//user has logged out...
setUser(null);
}
return () => {
//perform some cleanup actions
unsubscribe();
}
})
},[user,username])
The properties of the auth user seems to be displayed all fine except the displayName was trimmed. (The "test" was supposed to be "testing").