Sunday 29 March 2020

API Endpoint in Express stops working after 7 requests

Hey all, I have a simple login form that works fine with Node, Express, and React. If I make around 8 requests that are wrong(correct username, wrong password) it stops working and I cannot login even with the correct credentials until I have restart the server. Take a look at my code, if you've had an issue like this before, please shed some light on how you fixed it.. Thank you! I thought it may be because I don't call res.send or res.end if the call is unsuccessful, but I tried adding that and the problem still persists. No error logging.users.post('/login', (req,res) => { User.findOne({ where: { email: req.body.email } }) .then(user => { if(user) { if(bcrypt.compareSync(req.body.password,user.password)) { let token = jwt.sign(user.dataValues, process.env.SECRET_KEY, { expiresIn: 1440 }) res.send(token) } } else { res.status(400).json({error: "User Does not exist"}) } }) .catch(err => { res.status(400).json({error: err}) }) })

Submitted March 29, 2020 at 06:23PM by CharliePrograms12

No comments:

Post a Comment