Home > Software design >  post route for login page is pending request in browser with express node js
post route for login page is pending request in browser with express node js

Time:10-03

The router is pending not responding (pending in request)

 router.post('/loginpost',(req,res,next)=>{
           var email=req.body.email;
           var password=req.body.password;
           var selectsql=`SELECT * FROM client WHERE email='${email}' AND password='${password}'`
            database.query(selectsql, (err,data)=>{
              if (data.length>0){
                req.session.email=email
              res.json({datalogin:'success'})
            res.end()
              }
         })
    
    })

CodePudding user response:

If data.length > 0 isn't true, then you never call res.json() so you never send a response.

Either:

  • You have an error
  • The credentials you sent are wrong
  • You don't have a body parsing middleware capable of handling the format of the data you are sending

You need to:

  • Test for err in case there is an error condition
  • Handle the case where isn't exactly one match (e.g. when the username and password are wrong)

and do some debugging to figure out which of the three failure states I listed above is the one you are triggering.

  • Related