![](/img/trans.png)
[英]TypeError: Cannot read properties of undefined (reading 'email') with registration
[英]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");
});
代碼在此行 body.email 部分中顯示錯誤:
常量用戶 = 等待 User.findOne({ email: req.body.email });
你應該做
res.body.email 根據您的代碼在 req.body.email 的地方
因為在 post async function 你寫的是 (res, req) 而不是 (req, res)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.