【发布时间】:2022-09-27 21:30:22
【问题描述】:
当我尝试在 express 中进行身份验证时,会出现以下错误。但是如果成功登录没有错误。
这是我的代码:
exports.loginUser = async (req, res) => {
try {
const user = await User.findOne({ username: req.body.username });
!user && res.status(400).json(\"Wrong credentials!\");
const validated = await bcrypt.compare(req.body.password,user.password);
!validated && res.status(400).json(\"Wrong credentials!\");
const { password, ...others } = user._doc;
res.status(200).json(others);
} catch (err) {
res.status(500).json(err);
}
};
这是错误: Server crush
标签: node.js express authentication