How to update profile (displayName) firebase in React Native?

Viewed 6231

I found a problem to update profile firebase in React Native, I try to look for example but fails all, maybe you can give me advices or you can correct my script.

firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
    .then(
      (user)=>{
        if(user){
          user.updateProfile({
            displayName: 'Frank S. Andrew'
          }).then((s)=> {
            this.props.navigation.navigate('Account');
          })
        }
    })
    .catch(function(error) {
      alert(error.message);
    });

I try to follow all examples, in the alert shows message 'user.updateProfile is not a function'.

Please anyone help me how to update profile (displayName) firebase in React Native.

Thanks.

1 Answers

The createUserWithEmailAndPassword method returns a UserCredential object. This is not a User itself, but has a user property, which is a User object.

So what you need it:

firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
    .then((userCredentials)=>{
        if(userCredentials.user){
          userCredentials.user.updateProfile({
            displayName: 'Frank S. Andrew'
          }).then((s)=> {
            this.props.navigation.navigate('Account');
          })
        }
    })
    .catch(function(error) {
      alert(error.message);
    });
Related