【问题标题】:How we get username in firebase?我们如何在firebase中获取用户名?
【发布时间】:2021-10-08 22:43:38
【问题描述】:

在 firebase 中,我们使用 createUserWithEmailAndPassword 创建带有电子邮件和密码的用户。但是当我们验证令牌并获取 firebase 用户时,它会返回一些属性,如电子邮件、用户 ID、uid、名称等。在这里,我们只发送电子邮件和密码,然后我们如何获取用户名,即使我们没有将用户名传递给 firebase。我知道这很愚蠢,但我无法理解它是如何工作的。请帮帮我。

【问题讨论】:

    标签: firebase firebase-authentication


    【解决方案1】:

    试试这个

        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        // Name, email address etc
        String name = user.getDisplayName();
        String email = user.getEmail();
    }
    

    【讨论】:

      【解决方案2】:

      如果您尝试访问firebase.auth().currentUser.displayName,那么它将记录undefined,因为您从未设置过显示名称。您应该在用户注册后使用updateProfile 方法更新名称。

      firebase.auth().createUserWithEmailAndPassword().then((userCred) => {
        const {user} = userCred
        user.updateProfile({displayName: "myNewName"}).then(() => {
          console.log("Name Updated")
          console.log(firebase.auth().currentUser.displayName)
        })
      })
      

      【讨论】:

        猜你喜欢
        • 2020-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-05
        • 2023-01-20
        • 1970-01-01
        • 2020-08-31
        相关资源
        最近更新 更多