Hello how can I set username on Signup for Firebase User. I use firebase Authentication API. I thought about try / catch block and setting User properties like
const user = auth.currentUser;
user.name = 'John123'
Is it possible?
const onSubmitHandler = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
createUserWithEmailAndPassword(auth, email, password)
}
Firebase Authentication has a display name for each user, which can be whatever you want it to be. To set it, call updateProfile as shown in the documentation on updating the user's profile:
await createUserWithEmailAndPassword(auth, email, password);
updateProfile(auth.currentUser, {
displayName: "John123"
})
It is full solution
const onSubmitHandler = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
const createUser = async ( ) => {
await createUserWithEmailAndPassword(auth, email, password)
updateProfile(auth.currentUser!, {
displayName: "John123" // it can be a value of an input
})
}
createUser()
}