我的中间件代码是:
exports.isAuthenticated = (req, res, context) => {
return new Promise((resolve, reject) => {
return passport.authenticate('jwt',{session: false}, (err, user, info) => {
if(err) {
res.status(500).send({message: 'Internal Server Error'})
return resolve(context.stop);
}
if(user) {
return resolve(context.continue);
} else {
res.status(401).send({message: 'Unauthorized'})
return resolve(context.stop)
}
})(req, res);
});
}
我的结语代码是:
// Data plan REST API
const dataplan = epilogue.resource({
model: global.db.DataPlan,
endpoints: ['/api/dataplan', '/api/dataplan/:id']
});
dataplan.all.auth(middleware.isAuthenticated)
dataplan.use(require('./epilogue/dataplan.js'))
我dataplan.js
的是:
module.exports = {
list: {
auth: async function (req, res, context) {
console.log(req.user)
return context.continue
},
send: {
....
但是 my中的 myreq.user
是空的list.auth
。我究竟做错了什么?