Node.js 如何将NodeJ上的登录数据与MongoDB中的注册用户进行比较
我只需要知道当用户Node.js 如何将NodeJ上的登录数据与MongoDB中的注册用户进行比较,node.js,express,mongoose,postman,Node.js,Express,Mongoose,Postman,我只需要知道当用户login尝试登录时,如何在MongoDB中比较电子邮件/密码如果用户输入了错误的Crediantal则应发出一封无效的通行证/电子邮件 我只是想知道如何比较价值观。你的一点时间可以拯救我的一天 function login() { app.post('/login/', async(req, res) => { const query = new Model({ email: req.body.email, passwor
login
尝试登录时,如何在MongoDB中比较电子邮件/密码如果用户输入了错误的Crediantal
则应发出一封无效的通行证/电子邮件
我只是想知道如何比较价值观。你的一点时间可以拯救我的一天
function login() {
app.post('/login/', async(req, res) => {
const query = new Model({
email: req.body.email,
password: req.body.password
});
});
}
//here's the Schema and Mongoose Connection
mongoose.connect("mongodb://localhost:27017/Login", { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log('connected mfs'))
.catch((err) => console.error("error found...", err));
const LoginSchema = new mongoose.Schema({
email: { type: String, required: true },
password: { type: String, required: true }
});
//connection
const port = process.env.port || 3000;
app.listen(port, () => console.log(`listening to port ${port}`));
//here's the headers
const express = require('express');
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extend: true }));
const mongoose = require('mongoose')
第一次导入bcrypt。
并在您的登录功能中执行以下代码
import bcrypt from 'bcryptjs';
let user = await model.findOneUser({ email: this.req.body.email});
if (user == null) {
return sendResponse(this.res, 400, FAILED_MSG, 'Incorrect id or password.');
}
let isValidPassword = await bcrypt.compare(this.req.body.password, user.password);
if (!isValidPassword) {
return sendResponse(this.res, 400, FAILED_MSG, 'Incorrect id or password.');
}
// do success code
我在发布
unhandledPromisejectionWarning:TypeError:无法读取未定义的属性“body”时遇到此错误,或者此unhandledPromisejectionWarning:ReferenceError:未定义模型
model=“您的登录架构”。在函数前面使用“async”关键字,如“async function login()”。并对req.body.com使用“body解析器”。请通过电子邮件向我寻求进一步帮助