How do I set the displayName of Firebase user?

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


firebase
      .auth()
      .createUserWithEmailAndPassword(newUser.email, newUser.password)
      .then((res) => {
        const user = firebase.auth().currentUser;
        return user.updateProfile({
          displayName: newUser.name
        })
      })

This worked for me.


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