在路由中设置的中间件,去掉中间件正常,加上中间件status=404了?
//中间件
const jwt = require('jsonwebtoken');
const { config } = require('./../utils/config');
module.exports = () => {
return async function isAuth(ctx, next) {
const token = ctx.cookies.get('token', { signed: false });
if (token) {
jwt.verify(token, config.privateKey, async function(err, decoded) {
if (err) {
console.log(err);
ctx.body = {
code: 5001,
data: null,
msg: 'token失效!'
};
return;
}
ctx.request.body.sessionKey = decoded.sessionKey;
ctx.request.body.token = token;
await next();
});
} else {
ctx.body = {
code: 5003,
data: null,
msg: '请求出错,无token!'
};
}
};
};
//路由
const isAuth = middleware.isAuth();
apiRouter.post('/updateUserInfo', isAuth, clientUserInfo.updateUserInfo);
//控制器
//有返回body内容