类型错误: 无法读取未定义的读取'email'的属性


router.post('/login', async (res, req) => {
const{error} = loginValidation(req.body);
if (error) return res.status(400).send(error.details[0].message);

//user validation
const user = await User.findOne({ email: req.body.email });
if (!user) return res.status(400).send("Email doesn't exists");
//checking password
const validPass = await bcrypt.compare(req.body.password, user.password);
if (!validPass) return res.status(400).send('Invalid Password')

res.send("logged in");
});

代码在这行正文中显示错误。电子邮件部分:

const user=await user.findOne({email:req.body.email}(;

vscode错误图像

您应该执行

res.body.email根据您的代码

因为在post-async函数中,您编写了(res,req(而不是(req,res(

最新更新