Commit fdf34ed3 authored by 姜登's avatar 姜登

登录token问题

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