【问题标题】:Why when remote debug is not active my user is null and when its active its an object?为什么当远程调试未激活时,我的用户为空,而当它激活时,它是一个对象?
【发布时间】: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


    【解决方案1】:

    好吧,我不能直接从您的代码中回答您的问题,但是您应该知道,当您启用远程 js 调试时,您使用的是浏览器的 JS 运行时而不是移动运行时。因此,这两个运行时可能缺少函数或不同的实现。

    更多信息请参考这篇文章:You should not always rely on remote debugging (React Native)

    【讨论】:

    • 很高兴为您提供帮助!另外,请尝试不时关闭远程调试,看看是否有什么突然中断。
    • 我一定会这样做的!谢谢。
    • T.sagiv 我也有同样的问题你找到解决办法了吗?
    • 我也遇到了同样的问题。
    猜你喜欢
    • 1970-01-01
    • 2017-03-23
    • 1970-01-01
    • 2011-06-24
    • 1970-01-01
    • 2020-03-02
    • 2018-08-12
    • 2016-12-29
    • 1970-01-01
    相关资源
    最近更新 更多