【发布时间】:2017-08-13 09:46:33
【问题描述】:
当我尝试为 此代码 中的用户创建令牌时:
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);
}
})
},
//
};
我收到此错误:
未处理的拒绝类型错误:将循环结构转换为 JSON 在 Object.stringify (本机) 在 toString (/home/omarou/Documents/Projet/PharmaLiv/node_modules/jws/lib/tostring.js:9:15) 在 jwsSecuredInput (/home/omarou/Documents/Projet/PharmaLiv/node_modules/jws/lib/sign-stream.js:12:34) 在 Object.jwsSign [作为符号] (/home/omarou/Documents/Projet/PharmaLiv/node_modules/jws/lib/sign-stream.js:22:22) 在 Object.module.exports [作为标志] (/home/omarou/Documents/Projet/PharmaLiv/node_modules/jsonwebtoken/sign.js:146:16) 在 Model.Patient.find.then.patient (/home/omarou/Documents/Projet/PharmaLiv/server/controllers/patients.js:27:39) 在 Model.tryCatcher (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/util.js:16:23) 在 Promise._settlePromiseFromHandler (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/promise.js:512:31) 在 Promise._settlePromise (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/promise.js:569:18) 在 Promise._settlePromise0 (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/promise.js:614:10) 在 Promise._settlePromises (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/promise.js:693:18) 在 Async._drainQueue (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/async.js:133:16) 在 Async._drainQueues (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/async.js:143:10) 在 Immediate.Async.drainQueues (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/async.js:17:14) 在 runCallback (timers.js:651:20) 在 tryOnImmediate (timers.js:624:5)
controllers/patients.js:27:39参考我代码上的jwt.sign方法
它表明它来自 jwt.sign 方法
谁能告诉我怎么回事?
【问题讨论】:
标签: javascript json request jwt