[英]I can create firebase user using this code, but how can I add display Name, phone Number and other information in default firebase user table? Thanks
This is my funcation code.这是我的功能代码。
const signUpFun = () => {
if (isValidForm()) {
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
setbitdata({});
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
setEmailAndPasswordCheck(true)
setTimeout(() => {
setEmailAndPasswordCheck(false)
}, 3500)
});
}
}
import { getAuth, updateProfile } from "firebase/auth";
const auth = getAuth();
updateProfile(auth.currentUser, {
displayName: "My Name", photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(() => {
// Profile updated!
}).catch((error) => {
// An error occurred
});
If you are using firebase version 8, then you should use like these:如果您使用的是 firebase 版本 8,那么您应该像这样使用:
import firebase from "firebase";
const user = firebase.auth().currentUser;
user.updateProfile({
displayName: "My Name",
photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(() => {
// Update successful
}).catch((error) => {
// An error occurred
});
Firebase have very great documentation, you should probably read that, as like @Alexandros Giotas mentioned the link for official Documentation for your question Firebase 有非常棒的文档,您可能应该阅读它,就像@Alexandros Giotas 提到您的问题的官方文档链接一样
You're probably looking for the updateProfile
method.您可能正在寻找
updateProfile
方法。
Using modular imports:使用模块化导入:
import { getAuth, updateProfile } from "firebase/auth";
const auth = getAuth();
updateProfile(auth.currentUser, {
displayName: "Your display name here",
// more updating..
}).then(() => {
// Success
}).catch((e) => {
// Handle errors.
});
Remember that updateProfile
returns a Promise which you should handle, with either then() & catch()
as shown above or await
if you're updating within an async
function.请记住,
updateProfile
返回一个您应该处理的 Promise,使用then() & catch()
如上所示,或者如果您在async
函数中更新,则使用await
。
I encourage you to read the Firebase docs on updating a user's profile .我鼓励您阅读有关更新用户个人资料的 Firebase 文档。 There are more code snippets there, that answer your question probably better than I did.
那里有更多的代码片段,可能比我更好地回答你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.