【问题标题】: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我可以使用此代码创建 firebase 用户,但如何在默认 firebase 用户表中添加显示名称、电话号码和其他信息?谢谢
【发布时间】:2022-12-31 21:15:54
【问题描述】:

这是我的功能代码。

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)
            });
    }
}

【问题讨论】:

    标签: javascript firebase firebase-authentication


    【解决方案1】:
    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
    });
    

    如果您使用的是 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 有非常棒的文档,您可能应该read,就像@Alexandros Giotas 提到的官方文档链接一样

    【讨论】:

    【解决方案2】:

    您可能正在寻找 updateProfile 方法。
    使用模块化导入:

    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.
    });
    

    请记住,updateProfile 返回一个您应该处理的 Promise,如上所示使用 then() & catch()await 如果您在 async 函数中更新。

    我鼓励您阅读Firebase docs on updating a user's profile。 那里有更多代码 sn-ps,可能比我更好地回答了您的问题。

    【讨论】:

      猜你喜欢
      • 2019-11-16
      • 1970-01-01
      • 1970-01-01
      • 2018-03-12
      • 2018-03-28
      • 1970-01-01
      • 1970-01-01
      • 2016-11-18
      • 1970-01-01
      相关资源
      最近更新 更多