【发布时间】:2019-03-14 18:05:57
【问题描述】:
我在后端的登录功能接受来自 POSTMAN 的 xxx-form-encoded 格式的参数。当我将格式更改为 application/json 时出现错误。关于如何接收 request.body 的任何想法?
authenticate: function(req, res, next) {
userModel.findOne({email:req.body.email}, function(err, userInfo){
if (err) {
next(err);
} else {
console.log(`The bcrypt value: ${bcrypt.compareSync(req.body.password, userInfo.password)}`)
if(userInfo != null && bcrypt.compareSync(req.body.password, userInfo.password)) {
const token = jwt.sign({id: userInfo._id}, req.app.get('secret'), { expiresIn: '1h' });
res.json({status:"success", message: "user found!!!", data:{user: userInfo, token:token}});
}else{
res.json({status:"error", message: "Invalid email/password!!!", data:null});
}
}
});
}
【问题讨论】: