javascript - nodejs登录系统密码未定义
问题描述
我正在用 Nodejs、Express 和 MongoDB 构建一个登录系统。当我单击登录按钮时,我不断被重定向到“您未通过验证”页面。我决定控制台记录密码以查看发生了什么,并且用户输入的密码以及存储在数据库中的密码由于某种原因出现为未定义(在 console.logs 处未定义)。我怎样才能解决这个问题?
app.post("/login", (req, res) => {
//Get user fields
const userEmail = req.body.loginEmail;
const userPass = req.body.userPass;
//Is user in database?
User.find({ email: userEmail }, (err, user) => {
if (!err) {
//Compare password to database password
bcrypt.compare(userPass, user.password, (err, result) => {
console.log(user.pasword);
console.log(userPass);
//If user pass in database, check if verified & redirect to success
if (userPass === user.password) {
if (user.isVerified) {
res.redirect("/success");
} else {
res.send(
"You are not verified. Please check your email to access your account."
);
}
} else {
res.send("Incorrect password");
}
});
} else {
res.send(err);
}
});
});
解决方案
推荐阅读
- javascript - 如何在我的组件上看到我的数组?/ 反应 / Javascript
- date - 当从工作簿的另一页提供输入时,文本框需要格式化日期而不是更改为代码编号
- hashmap - 如何在有超过 10 列且只有一行数据的 webtable 上使用 Hashmap
- php - PDO中命名参数的规则是什么?
- python - 显示出现在字符串列中的字符串列表中的第一个字符串
- flutter - 谷歌地图标记相关问题
- vespa - 我无法在 vespa 中添加数据
- pytorch - Colab pro 不提供超过 16 GB 的内存
- angular - 具有不同上下文路径的 Angular 应用程序
- javascript - JS 函数startsWith 无法提供正确的输出。我的代码中的代码异味是什么?