admin管理员组文章数量:1325236
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)
}
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)
}
Share
Improve this question
edited Feb 5, 2022 at 23:51
Frank van Puffelen
600k85 gold badges889 silver badges859 bronze badges
Recognized by Google Cloud Collective
asked Feb 5, 2022 at 23:39
KayKay
8914 gold badges13 silver badges35 bronze badges
3 Answers
Reset to default 7Firebase 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"
})
const result = await createUserWithEmailAndPassword(
auth,
email,
password
);
await updateProfile(result.user, {
displayName: username,
});
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()
}
本文标签: javascriptHow to set username in Firebase authStack Overflow
版权声明:本文标题:javascript - How to set username in Firebase auth - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742166163a2425863.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论