-1

router.post("/auth", async (req, res) => { const { username, password } = req.body;

const user = await login.findOne({ where: { username: username } });

if (!user) res.json({ error: "User Doesn't Exist" });

bcrypt.compare(password, user.password).then((match) => {
  if (!match) res.json({ error: "Wrong Username And Password Combination" });

  res.json("YOU LOGGED IN!!!");
});

})

module.exports = router;enter image description here

1 Answers1

0

This error was due to not catching errors properly the correct way of catching errors will be like:

router.post("/auth", async (req, res) => {
  const { username, password } = req.body; 
  const user = await login.findOne({
   where: { username: username }
  });

  if (!user)
    res.json({ error: "User Doesn't Exist" })
  else {
    bcrypt
      .compare(password, user.password)
      .then((match) => {
        if (!match)
          res.json({ error: "Wrong Username And Password Combination" })
        else {
          res.json("Logged in");
        }
      });
  }
})
module.exports = router;
Tyler2P
  • 2,324
  • 26
  • 22
  • 31