简体   繁体   English

我可以使用此代码创建 firebase 用户,但如何在默认 firebase 用户表中添加显示名称、电话号码和其他信息? 谢谢

[英]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.

相关问题 如何使用 firebase 和 javascript 将图像发送给其他用户? - How can I send image to other user by using firebase and javascript? 如何在使用电话号码注册期间将名称和 email 添加到 Firebase 用户帐户? - How do I add name and email to a Firebase user account during signup with phone number? 使用JavaScript和Firebase,如何创建用户特定的对象? - Using JavaScript and Firebase, how can I create user specific objects? 我如何使用 firebase auth 在 nodejs 的服务器端验证用户电话号码 - How can i authenticate user phone number on server side in nodejs with firebase auth 如何使用 javascript 在 firebase 中添加用户的额外信息,例如显示名称? - How to add user's extra information such as display name in firebase using javascript? 如何从firebase检索信息并使用javascript将其显示在HTML表格中 - How can I retrieve information from firebase and display it in a HTML table using javascript 如何使用 Firebase signInWithCredentials() 设置用户的显示名称和电子邮件 - How can I set a user's display name and email with Firebase signInWithCredentials() 如何使用 Firebase 实时数据库将信息从一个用户发送到另一个用户? - How can I send information from one user to another using Firebase realtime database? 如何从 Firebase 获取用户个人资料和名称? - How can I get the user profile and name from Firebase? 使用 Firebase v9,如何在使用 gmail 登录时将用户添加到用户集合中? - Using Firebase v9, how can I add the user to the user collection upon logging in with gmail?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM