簡體   English   中英

TypeError:無法讀取未定義閱讀“電子郵件”的屬性

[英]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 });

vscode 錯誤圖片

你應該做

res.body.email 根據您的代碼在 req.body.email 的地方

因為在 post async function 你寫的是 (res, req) 而不是 (req, res)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM