Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase身份验证。一般查询_Firebase_React Native_Firebase Authentication - Fatal编程技术网

Firebase身份验证。一般查询

Firebase身份验证。一般查询,firebase,react-native,firebase-authentication,Firebase,React Native,Firebase Authentication,我目前正在创建一个react原生应用程序,并在物理像素2上使用exp进行测试。当我加载应用程序时,componentDidMount中有以下内容: componentDidMount = () => { firebase.auth().onAuthStateChanged((user)=>{ if (user) { //this.setState({userid: user.uid}); //I added this to see

我目前正在创建一个react原生应用程序,并在物理像素2上使用exp进行测试。当我加载应用程序时,componentDidMount中有以下内容:

componentDidMount = () => {

    firebase.auth().onAuthStateChanged((user)=>{ 
        if (user) {
            //this.setState({userid: user.uid}); //I added this to see if it was the below slowing things down (it is not)
            firebase.database().ref('/Users/'+user.uid+'/Public/').once('value')
            .catch(err=>{console.log(err)})
            .then(snapshot=>{

                let username = snapshot.child('Username').val();
                    this.setState({username: username, userid: user.uid});
                });

        } else {

            this.setState({ user: null, username: null});
        }

    });}
我的目标是,如果用户未通过身份验证,则将其引导到登录页面。否则,直接进入内页。我的代码工作正常,这确实发生了(万岁!)

然而,当我加载我的应用程序时,需要几秒钟(可能是10秒钟),应用程序才会意识到我已经登录。这意味着它将显示登录页面10秒钟,然后开始显示内部页面。有人知道为什么
.onAuthStateChanged
要花这么长时间才能注册,而实际上我还是从上次会话中登录的吗?还有,有没有办法让我知道我在登录页面是因为我根本没有登录,还是因为应用程序还没有意识到我已经登录?这是非常尴尬的用户必须登录每次,然后中途通过输入他们的详细信息,登录lol


一如既往,我们非常感谢您的帮助。

您好,我认为firebase检查您是否通过身份验证需要多长时间,您对此无能为力。但是,我建议显示加载屏幕或微调器,直到您知道是否将用户引导到登录页或登录页。但我如何知道是否将用户引导到登录页或登录页?问题是我不知道它是否将进行身份验证,因此我无法实现加载屏幕。