【发布时间】:2018-11-02 14:55:02
【问题描述】:
当我远程使用调试 js 时,我的用户 not 为空,而当我不远程使用调试 js 时,我的用户为空。 这是我的代码,用于检查用户是否已登录,然后将他引导到正确的组件:
componentDidMount(){
that=this;
this.authSubscription = firebaseRef.auth().onAuthStateChanged((user) => {
if (user) {
firebaseRef.database().ref('/users/'+user.uid+'/info').once('value').then(function(snapshot) {
if (snapshot.val() !== null) {
that.setState({
haveInfo: true,
loading: false,
user: true,
})
}else{
this.setState({
loading: false,
user: true,
haveInfo: false,
})
}
});
}else{
that.setState({
user: false,
haveInfo: false,
loading: false,
});
}
});
}
render() {
if (this.state.loading) {
//Welcome screen
return <Welcome />
}
if (this.state.user) {
if (this.state.haveInfo) {
//the user set up his info
return <Main />
}else{
//If the user didnt set up his info
return <ProfileSettingUp />
}
}
// If the user is null
return <MainLogToSignUpProceses />
}
我不知道为什么会这样。 感谢您的帮助。
【问题讨论】:
标签: javascript reactjs firebase react-native firebase-authentication