简体   繁体   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");
});

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 });

vscode error image vscode 错误图片

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.

相关问题 类型错误:无法通过注册读取未定义的属性(读取“电子邮件”) - TypeError: Cannot read properties of undefined (reading 'email') with registration 类型错误:无法读取未定义的属性(读取“路径”) - TypeError: Cannot read properties of undefined (reading 'path') TypeError:无法读取未定义的属性(读取“forEach”) - TypeError: Cannot read properties of undefined (reading 'forEach') TypeError:无法读取未定义的属性(读取'indexOf') - TypeError: Cannot read properties of undefined (reading 'indexOf') TypeError:无法读取未定义的属性(读取'forEach) - TypeError: Cannot read properties of undefined (reading 'forEach) TypeError:无法读取未定义的属性(读取“命令”) - TypeError: Cannot read properties of undefined (reading 'commands') TypeError:无法读取未定义的属性(读取“最高”) - TypeError: Cannot read properties of undefined (reading ‘highest’) TypeError:无法读取未定义的属性(读取“findOne”) - TypeError: Cannot read properties of undefined (reading 'findOne') TypeError:无法读取未定义的属性(读取“发送”) - TypeError: Cannot read properties of undefined (reading 'send') TypeError:无法读取未定义的属性(读取“useParams”) - TypeError: Cannot read properties of undefined (reading 'useParams')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM