Commit b621cdd5 authored by 任国军's avatar 任国军

fix jwt err status_code

parent dfcd7a72
Pipeline #21853 passed with stage
in 3 seconds
......@@ -18,7 +18,7 @@ const OPENID = Symbol('Context#openId');
module.exports = {
failed(message) {
const method = this.request.method.toLowerCase();
this.throw(422, message);
this.throw(400, message);
},
success(data = false) {
const method = this.request.method.toLowerCase();
......
......@@ -9,7 +9,7 @@ module.exports = {
const { ctx } = this;
const bearerToken = ctx.request.header.authorization;
if (!bearerToken) {
ctx.failed('error auth');
ctx.throw(401, 'error auth');
}
return bearerToken && bearerToken.replace('Bearer ', '');
},
......@@ -18,9 +18,12 @@ module.exports = {
async verify_token(ctx) {
const token = this.get_jwt(ctx);
const decode_res = await ctx.service.jwt.decode_token(token);
if (ctx.isEmpty(decode_res)) {
ctx.throw(401, 'jwt校验失败');
}
const token_black = await this.app.memcache.get('auth_token_' + decode_res.data.user_uuid);
if (token_black == token) {
ctx.failed('jwt校验失败');
ctx.throw(401, 'jwt校验失败');
}
ctx.setUserUuid(decode_res.data.user_uuid);
ctx.setOpenId(decode_res.data.openid);
......
......@@ -19,7 +19,16 @@ class JWTService extends Service {
async decode_token(token) {
const { ctx } = this;
return ctx.app.jwt.decode(token, ctx.app.config.jwt.secret);
let ret = {};
try {
ret = await ctx.app.jwt.decode(token, ctx.app.config.jwt.secret);
} catch (err) {
ctx.throw(401, 'jwt解密失败');
}
if (ctx.isEmpty(ret)) {
ctx.throw(401, 'jwt解密失败');
}
return ret;
}
async del_token(token) {
......
......@@ -26,8 +26,8 @@ module.exports = appInfo => {
};
exports.bodyParser = {
jsonLimit: '1mb',
formLimit: '1mb',
jsonLimit: '10mb',
formLimit: '10mb',
};
return config;
......
......@@ -192,8 +192,8 @@ module.exports = appInfo => {
config.COURSE_WX_SECRET = 'a1b2d32b018988176181497bd74a0b7d';
exports.bodyParser = {
jsonLimit: '1mb',
formLimit: '1mb',
jsonLimit: '10mb',
formLimit: '10mb',
};
return config;
......
......@@ -135,8 +135,8 @@ module.exports = appInfo => {
};
exports.bodyParser = {
jsonLimit: '1mb',
formLimit: '1mb',
jsonLimit: '10mb',
formLimit: '10mb',
};
config.CDN_BASE_URL = 'https://r.51gjj.com/image/';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment