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

fix jwt bug

parent bf62b6fa
Pipeline #21901 passed with stage
in 3 seconds
...@@ -21,9 +21,9 @@ module.exports = { ...@@ -21,9 +21,9 @@ module.exports = {
if (ctx.isEmpty(decode_res)) { if (ctx.isEmpty(decode_res)) {
ctx.throw(401, 'jwt校验失败'); ctx.throw(401, 'jwt校验失败');
} }
const token_black = await this.app.memcache.get('auth_token_' + decode_res.data.user_uuid); const token_black = await this.app.memcache.get('course_auth_token_' + decode_res.data.user_uuid);
if (token_black == token) { if (token_black !== token) {
ctx.throw(401, 'jwt校验失败'); ctx.throw(401, 'token不一致');
} }
ctx.setUserUuid(decode_res.data.user_uuid); ctx.setUserUuid(decode_res.data.user_uuid);
ctx.setOpenId(decode_res.data.openid); ctx.setOpenId(decode_res.data.openid);
......
...@@ -63,7 +63,7 @@ class UserService extends Service { ...@@ -63,7 +63,7 @@ class UserService extends Service {
// 手机号登录 // 手机号登录
async loginByPhone(input) { async loginByPhone(input) {
const { ctx } = this; const { ctx, app } = this;
const phone = input.phone; const phone = input.phone;
const code = input.code; const code = input.code;
...@@ -94,6 +94,7 @@ class UserService extends Service { ...@@ -94,6 +94,7 @@ class UserService extends Service {
}; };
await ctx.app.memcache.set(key, value); await ctx.app.memcache.set(key, value);
const authToken = await this.service.jwt.apply({ user_uuid: userInfo.uuid, openid: userInfo.openid }); const authToken = await this.service.jwt.apply({ user_uuid: userInfo.uuid, openid: userInfo.openid });
await app.memcache.set('course_auth_token_' + userInfo.uuid, authToken);
const ret = { const ret = {
user_uuid: userInfo.uuid, user_uuid: userInfo.uuid,
...@@ -136,6 +137,7 @@ class UserService extends Service { ...@@ -136,6 +137,7 @@ class UserService extends Service {
}; };
await app.memcache.set(key, value); await app.memcache.set(key, value);
const authToken = await this.service.jwt.apply({ user_uuid: userInfo.uuid, openid: userInfo.openid }); const authToken = await this.service.jwt.apply({ user_uuid: userInfo.uuid, openid: userInfo.openid });
await app.memcache.set('course_auth_token_' + userInfo.uuid, authToken);
const ret = { const ret = {
user_uuid: userInfo.uuid, user_uuid: userInfo.uuid,
...@@ -225,6 +227,7 @@ class UserService extends Service { ...@@ -225,6 +227,7 @@ class UserService extends Service {
}; };
await app.memcache.set(key, value); await app.memcache.set(key, value);
const authToken = await this.service.jwt.apply({ user_uuid: data.uuid, openid: user.openid }); const authToken = await this.service.jwt.apply({ user_uuid: data.uuid, openid: user.openid });
await app.memcache.set('course_auth_token_' + data.uuid, authToken);
const ret = { const ret = {
user_uuid: data.uuid, user_uuid: data.uuid,
......
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