0
有人可以帮助我弄清楚为什么bcrypt.compareSync
功能不会对我的情况下工作:bcrypt.compareSync不上sequelize工作
型号/ patient.js
const bcrypt = require('bcryptjs');
module.exports = (sequelize, Sequelize) => {
const Patient = sequelize.define('Patient', {
email: {
type: Sequelize.STRING,
allowNull: false,
},
password: {
type: Sequelize.STRING,
allowNull: false,
},
}, {
classMethods: {
associate: (models) => {
// associations can be defined here
}
},
instanceMethods: {
//
verifyPassword: function(password,hash) {
bcrypt.compareSync(password,hash);
}
}
});
return Patient;
};
控制器/ patients.js EDITED
retrieve(req, res) {
return Patient
.find({
where: {
email: req.body.email,
}
})
.then(patient => {
const result = Patient.build().verifyPassword(req.body.password, patient.password);
if (!result) {
console.log('wrong password')
} else return res.status(201).send(patient);
})
}
我的要求应该返回患者对应于上要求输入的电子邮件地址和密码,但它返回此:
编辑:错误的问题解决了,但仍然得到错误的结果(它返回“密码错误”的字符串),甚至当我提出一个请求正确的密码。
那么错误是什么? – zerkms
我的请求没有任何回应,但它应该返回与请求中键入的电子邮件和密码相对应的患者。 –
你有'错误',你为什么不输出它?永远不要忽略错误,他们是有原因的。 – zerkms