如何在React Native中更新profile(displayName)firebase?

问题描述 投票:0回答:1

我发现在React Native中更新配置文件firebase有问题,我尝试查找示例但是全部失败,也许您可​​以给我建议或者您可以更正我的脚本。

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

我尝试按照所有示例,在警报显示消息'user.updateProfile不是函数'。

请任何人帮我如何在React Native中更新profile(displayName)firebase。

谢谢。

javascript firebase react-native firebase-authentication
1个回答
3
投票

createUserWithEmailAndPassword method返回UserCredential object。这不是User本身,但有一个user属性,这是一个User object

所以你需要它:

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);
    });
© www.soinside.com 2019 - 2024. All rights reserved.