登录校验bug修复
多客户端登录,返回相同的token
This commit is contained in:
zhongzb
2023-05-24 00:35:49 +08:00
parent 04ca1c452f
commit 8d226ae3bd
2 changed files with 14 additions and 6 deletions

View File

@@ -67,16 +67,24 @@ public class LoginServiceImpl implements LoginService {
@Override @Override
public String login(Long uid) { public String login(Long uid) {
//获取用户token
String token = jwtUtils.createToken(uid);
//存储到redis
String key = RedisKey.getKey(RedisKey.USER_TOKEN_STRING, uid); String key = RedisKey.getKey(RedisKey.USER_TOKEN_STRING, uid);
redisUtils.set(key, token, TOKEN_EXPIRE_DAYS, TimeUnit.DAYS);//token过期用redis中心化控制初期采用5天过期剩1天自动续期的方案。后续可以用双token实现 String token = redisUtils.getStr(key);
if (StrUtil.isNotBlank(token)) {
return token;
}
//获取用户token
token = jwtUtils.createToken(uid);
RedisUtils.set(key, token, TOKEN_EXPIRE_DAYS, TimeUnit.DAYS);//token过期用redis中心化控制初期采用5天过期剩1天自动续期的方案。后续可以用双token实现
return token; return token;
} }
@Override @Override
public Long getValidUid(String token) { public Long getValidUid(String token) {
return jwtUtils.getUidOrNull(token); boolean verify = verify(token);
return verify ? jwtUtils.getUidOrNull(token) : null;
}
public static void main(String[] args) {
System.out.println();
} }
} }

View File

@@ -75,7 +75,7 @@ public class NettyWebSocketServerHandler extends SimpleChannelInboundHandler<Tex
// 处理异常 // 处理异常
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
log.warn("异常发生,异常消息 ={}" + cause.getMessage()); log.warn("异常发生,异常消息 ={}" , cause.getMessage());
ctx.channel().close(); ctx.channel().close();
} }