How do I set the displayName of Firebase user?

前端 未结 3 1873
时光说笑
时光说笑 2020-12-29 05:20

According to the JS Auth documentation on the Firebase website, it only shows how to get the displayName and how to update displayName. So I tried to update it. But

相关标签:
3条回答
  • 2020-12-29 05:31

    I could´t use ({displayName: name}) directly (sintaxe error in editor). Then, I found another way:

    UserUpdateInfo updateInfo = UserUpdateInfo();
    updateInfo.displayName = name;
    result.user.updateProfile(updateInfo);
    

    This is in Dart (I am using Firebase with Flutter).

    0 讨论(0)
  • You have to chain the request:

    firebase.auth().createUserWithEmailAndPassword(email, password)
    .then(function(result) {
      return result.user.updateProfile({
        displayName: document.getElementById("name").value
      })
    }).catch(function(error) {
      console.log(error);
    });`
    
    0 讨论(0)
  • 2020-12-29 05:50
    firebase
          .auth()
          .createUserWithEmailAndPassword(newUser.email, newUser.password)
          .then((res) => {
            const user = firebase.auth().currentUser;
            return user.updateProfile({
              displayName: newUser.name
            })
          })
    

    This worked for me.

    0 讨论(0)
提交回复
热议问题