router.post("/auth",异步(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 =路由器;在这里输入图像描述
发布于 2022-06-23 04:53:56
此错误是由于没有正确捕获错误,捕获错误的正确方式如下:
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;https://stackoverflow.com/questions/72724579
复制相似问题