Commit fdf34ed3 authored by 姜登's avatar 姜登

登录token问题

parent b7d4be71
...@@ -10,9 +10,8 @@ module.exports = () => { ...@@ -10,9 +10,8 @@ module.exports = () => {
} }
const token_black = await ctx.app.memcache.get('yizhi_server_token' + token_data.data.user_id); const token_black = await ctx.app.memcache.get('yizhi_server_token' + token_data.data.user_id);
// ctx.logger.info('【token_black:】', token_black, token); // ctx.logger.info('【token_black:】', token_black, token);
if (token_black) ctx.app.logger.info('【sso token black:】', token_black, token); if (token_black !== token) {
if (token_black === token) { ctx.failed('无效的token');
ctx.failed('token 已失效');
} }
ctx.token = token || ''; ctx.token = token || '';
ctx.userId = token_data.data.user_id || ''; ctx.userId = token_data.data.user_id || '';
......
...@@ -5,7 +5,7 @@ const Service = require('egg').Service; ...@@ -5,7 +5,7 @@ const Service = require('egg').Service;
class JwtService extends Service { class JwtService extends Service {
async apply(data) { async apply(data) {
const { ctx } = this; const { ctx, config, app } = this;
const exp = Math.round(new Date().getTime() / 1000) + ctx.app.config.jwtExp; const exp = Math.round(new Date().getTime() / 1000) + ctx.app.config.jwtExp;
const secret = ctx.app.config.jwt.secret; const secret = ctx.app.config.jwt.secret;
const auth_token = ctx.app.jwt.sign( const auth_token = ctx.app.jwt.sign(
...@@ -15,6 +15,7 @@ class JwtService extends Service { ...@@ -15,6 +15,7 @@ class JwtService extends Service {
}, },
secret secret
); );
await app.memcache.set('yizhi_server_token' + data.user_id, auth_token, config.jwtExp);
return auth_token; return auth_token;
} }
...@@ -28,7 +29,7 @@ class JwtService extends Service { ...@@ -28,7 +29,7 @@ class JwtService extends Service {
const { app, config } = this; const { app, config } = this;
const token_data = await this.decode_token(token); const token_data = await this.decode_token(token);
const { user_id } = token_data.data; const { user_id } = token_data.data;
await app.memcache.set('yizhi_server_token' + user_id, token, config.jwtExp); await app.memcache.set('yizhi_server_token' + user_id, '', config.jwtExp);
return true; return true;
} }
} }
......
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