当我尝试创建一个令牌就像一个用户的代码:
const jwt = require('jsonwebtoken');
const passport = require('passport');
const Patient = require('../models').Patient;
module.exports = {
retrieve(req, res) {
return Patient
.find({
where: {
email: req.body.email,
}
})
.then(patient => {
if (!patient) return res.json({
success: false,
msg: 'Patient not found'
});
const result = Patient.build().verifyPassword(req.body.password, patient.password);
if (!result) {
return res.json({
success: false,
msg: 'wrong password'
});
} else {
const token = jwt.sign(patient, secret, {
expiresIn: 604800 // 1 week
});
return res.status(201).send(patient);
}
})
}, …Run Code Online (Sandbox Code Playgroud)