Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.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
Node.js 登录页面问题(一次又一次返回登录页面)_Node.js_Reactjs_Express - Fatal编程技术网

Node.js 登录页面问题(一次又一次返回登录页面)

Node.js 登录页面问题(一次又一次返回登录页面),node.js,reactjs,express,Node.js,Reactjs,Express,我试图登录一个帐户,该页面打开主页一秒钟,然后它突然回调到登录页面 app.post('/signin',(req,res)=>{ let success = 0; database.users.forEach((user)=>{ if ((req.body.email === user.email || req.body.mobile === user.mobile) && req.body.pass

我试图登录一个帐户,该页面打开主页一秒钟,然后它突然回调到登录页面

app.post('/signin',(req,res)=>{
    let success = 0;
    database.users.forEach((user)=>{
        if ((req.body.email === user.email || 
        req.body.mobile === user.mobile) &&
        req.body.password === user.password){
            res.json(user);
            success = 1;
        }
    })
    if(success===0){
        res.status(400).json('error logging in');       
    }
});
如果我注册了一个新帐户,然后再次使用已经存在的用户登录,那么登录页面将工作并转到主页

签名组件中的my submit()为

onSubmitSignin = () =>{
    const p = document.querySelector('.login-pblm');
      fetch('http://localhost:3001/signin',{
        method:'post',
        headers:{'content-Type':'application/json'},
        body: JSON.stringify({
          email: this.state.signinEmail,
          password: this.state.signinPswrd,
          username: this.state.signinUsername,
          mobile: this.state.signinMobileNo
        })
      })
      .then(res => res.json())
      .then(data => {
        if(data !== 'error logging in'){
          console.log("successs");
          p.classList.remove('active');
          this.props.loadUser(data);
          this.props.onRouteChange('home');
        }
        else{
          p.classList.add('active');
        }
      })
    }
我没有得到任何错误,但我得到了上述问题,如果我在第一次登录,即使用户已经注册。起初我犯了一个错误,比如

错误[ERR\u HTTP\u HEADERS\u SENT]:发送后无法设置头 给客户

由于这个原因,我在服务器端函数中设置了一个名为success的变量

请帮我解决这个问题