【问题标题】:How to update profile (displayName) firebase in React Native?如何在 React Native 中更新配置文件(displayName)firebase?
【发布时间】:2019-04-13 18:17:32
【问题描述】:

我发现在 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 中更新配置文件 (displayName) firebase。

谢谢。

【问题讨论】:

    标签: javascript firebase react-native firebase-authentication


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-10
      • 1970-01-01
      • 2018-01-16
      • 1970-01-01
      • 2017-09-07
      • 2020-01-16
      • 1970-01-01
      • 2020-08-25
      相关资源
      最近更新 更多