【发布时间】:2020-05-13 05:41:09
【问题描述】:
我有这个简单的代码
state = { email: '', password: '', userName: '', errorMessage: null }
handleSignUp = () => {
firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password).then((userInfo) =>{
userInfo.user.updateProfile({displayName: this.state.userName}).then((s) => {this.props.navigation.navigate('Navigator')})
})
.catch(error => this.setState({ errorMessage: error.message }))
}
在应用导航到导航器屏幕之前,一切都按预期进行。
在这里,当我登录 firebase.auth() 时,我得到了这个对象:
Object {
"displayName": null,
"email": "test6@gmail.com",
"phoneNumber": null,
"photoURL": null,
"providerId": "password",
"uid": "test6@gmail.com",
},
注意displayName 是如何为空的。
这就是问题所在......只有在软刷新后我才能得到:
Object {
"displayName": "Bro",
"email": "test6@gmail.com",
"phoneNumber": null,
"photoURL": null,
"providerId": "password",
"uid": "test6@gmail.com",
},
注意displayName 现在有一个值。
我错过了什么?我是否以错误的顺序使用.then()?承诺顺序不正确吗?
感谢任何建议!
【问题讨论】:
-
添加 setTimeout 导航以测试是否存在异步问题 userInfo.user.updateProfile({displayName: this.state.userName}).then((s) => {setTimeout(() => { this.props.navigation.navigate('Navigator')}, 2000)})
-
你可以试试 setTimeout,然后我们将转向正确的解决方案
标签: reactjs firebase react-native firebase-authentication react-navigation