【发布时间】:2020-06-09 17:56:31
【问题描述】:
这总是有用的,不知何故这对我不起作用:
我用来比较密码的东西:
router.post("/login", [
check('email', 'Email is required').isEmail(),
check('password', 'Password is required').not().isEmpty()
], async (req, res) => {
const { email, password } = req.body;
const errors = validationResult(req);
if ( !errors.isEmpty() || !email || !password ) {
return res.status(401).json({err: "Authentication failure"});
};
try {
const user = User.findOne({ email: email });
if(!user) {
return res.status(401).json({err: "Invalid username or password"});
}
const isValid = await bcrypt.compare(password, user.password); //// <-------HERE!!!!!
console.log("Not reaching here")
if (!isValidPassword) {
return res.status(401).json({err: "Invalid username or password"});
}
//if valid password
res.status(200).send("SUCCESS");
} catch (error) {
res.status(500).json({err: "Internal server error"});
}
})
有人可以帮帮我吗?这是我第一次被困在这里。提前致谢。
【问题讨论】:
-
它是否发送内部服务器错误响应?你在 catch 块中试过
console.log(error)吗? -
谢谢,我想通了。
标签: javascript node.js ajax express es6-promise