[英]TypeError: Cannot read properties of undefined reading '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");
});
The code is showing error ins this line body.email part:代码在此行 body.email 部分中显示错误:
const user = await User.findOne({ email: req.body.email });常量用户 = 等待 User.findOne({ email: req.body.email });
You should do你应该做
res.body.email on the place of req.body.email according to your code res.body.email 根据您的代码在 req.body.email 的地方
Because in post async function you wrote (res, req) instead of (req, res)因为在 post async function 你写的是 (res, req) 而不是 (req, res)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.