Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.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
Javascript 当firebase的电子邮件或密码错误时,应用程序崩溃_Javascript_Firebase_React Native_Firebase Authentication - Fatal编程技术网

Javascript 当firebase的电子邮件或密码错误时,应用程序崩溃

Javascript 当firebase的电子邮件或密码错误时,应用程序崩溃,javascript,firebase,react-native,firebase-authentication,Javascript,Firebase,React Native,Firebase Authentication,因此,我使用的是最新版本的react native,firebase+react native form validator。 当我尝试使用正确的电子邮件和密码与现有用户登录时,一切都很好,但是,当我插入错误的电子邮件或密码时,应用程序崩溃,我出现以下错误: 相关代码行为: state={email:'',密码:'',错误:'',加载:false} 用户登录=()=>{ this.setState({loading:true}); 这个。验证({ 电子邮件:{required:true,em

因此,我使用的是最新版本的react nativefirebase+react native form validator。 当我尝试使用正确的电子邮件和密码与现有用户登录时,一切都很好,但是,当我插入错误的电子邮件或密码时,应用程序崩溃,我出现以下错误:

相关代码行为:

state={email:'',密码:'',错误:'',加载:false}
用户登录=()=>{
this.setState({loading:true});
这个。验证({
电子邮件:{required:true,email:true},
密码:{required:true,minlength:5}
});
if(this.isFormValid()){
firebase.auth().signiWithEmailandPassword(this.state.email,this.state.password)
.然后(()=>Actions.partyzmain())
.catch(设置超时(()=>{
this.setState({error:'电子邮件或密码为inccorect!',密码:'',加载:false});
}, 5000));                 
}
否则{
if(this.isFieldInError('password')){
this.setState({error:'error password!',password:'',loading:false});
}
如果(此.isFieldInError(“电子邮件”)){
this.setState({error:'Invalid email address!',loading:false});
}
}

};您的代码似乎正确

唯一可能的问题可能是
setTimeout
,它在不同的范围内运行
this.setState
,正如我在错误屏幕中看到的,该屏幕显示了计时器的回溯

我建议您使用
async/await
并使用
try…catch
构造处理所有丢弃的文件

对于计时器,您可以使用以下方法:

const wait = (timer) => 
  new Promise((resolve) => {
    setTimeout(resolve, timer);
  })
总体代码为:

state = { email: '', password: '', error: '', loading: false }


userLogin = async () => {
  try {
        this.setState({ loading: true });

        this.validate({
            email: { required: true, email: true },
            password: { required: true, minlength: 5 }
        });

        if (!this.isFormValid()) {
            if (this.isFieldInError('password')) {
                this.setState({ 
                  error: 'Wrong password!', 
                  password: '', loading: false 
                });
            }

            if (this.isFieldInError('email')) {
                this.setState({ 
                  error: 'Invalid email address!', 
                  loading: false 
                });
            }
            return;
        }

        await firebase
                .auth()
                .signInWithEmailAndPassword(
                  this.state.email, 
                  this.state.password
                );
        Actions.partyzmain();
  }
  catch (error) {
      console.debug(error);

      if (error.code.startsWith('auth')) {
        await wait(1000);
        this.setState({ 
          error: 'Email or password are inccorect!', 
          password: '', 
          loading: false 
        });
      }
  }
};

您的代码似乎是正确的

唯一可能的问题可能是
setTimeout
,它在不同的范围内运行
this.setState
,正如我在错误屏幕中看到的,该屏幕显示了计时器的回溯

我建议您使用
async/await
并使用
try…catch
构造处理所有丢弃的文件

对于计时器,您可以使用以下方法:

const wait = (timer) => 
  new Promise((resolve) => {
    setTimeout(resolve, timer);
  })
总体代码为:

state = { email: '', password: '', error: '', loading: false }


userLogin = async () => {
  try {
        this.setState({ loading: true });

        this.validate({
            email: { required: true, email: true },
            password: { required: true, minlength: 5 }
        });

        if (!this.isFormValid()) {
            if (this.isFieldInError('password')) {
                this.setState({ 
                  error: 'Wrong password!', 
                  password: '', loading: false 
                });
            }

            if (this.isFieldInError('email')) {
                this.setState({ 
                  error: 'Invalid email address!', 
                  loading: false 
                });
            }
            return;
        }

        await firebase
                .auth()
                .signInWithEmailAndPassword(
                  this.state.email, 
                  this.state.password
                );
        Actions.partyzmain();
  }
  catch (error) {
      console.debug(error);

      if (error.code.startsWith('auth')) {
        await wait(1000);
        this.setState({ 
          error: 'Email or password are inccorect!', 
          password: '', 
          loading: false 
        });
      }
  }
};

auth.js第17行等。尝试查找调用的位置\auth.js第17行等。尝试查找调用的位置\t它表示“没有与此标识符对应的用户记录。用户可能已被删除。”@AdarWallerstein change
console。在我对
console的回答中出现错误
。debug
否则将显示红色屏幕:)它说“没有与此标识符对应的用户记录。用户可能已被删除。”@AdarWallerstein更改
控制台。错误
在我对
控制台的回答中。调试
否则将显示红色屏幕:)