|
|
@@ -26,8 +26,7 @@ class AuthHook
|
|
|
public function generateToken($payload): void
|
|
|
{
|
|
|
$userId = decrypt_data($payload->sub, Auth::$config['jwt_secret']);
|
|
|
- $userType = $payload->aud;
|
|
|
- $this->cache->remember(self::TOKEN_INFO . $userType . ':' . $userId, (array) $payload, $payload->exp - time());
|
|
|
+ $this->cache->remember(self::TOKEN_INFO . $payload->aud . ':' . $userId . ':' . $payload->jti, (array) $payload, $payload->exp - time());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -57,14 +56,8 @@ class AuthHook
|
|
|
$remainingTime = $payload->exp - time();
|
|
|
if ($remainingTime > 0) {
|
|
|
$userId = decrypt_data($payload->sub, Auth::$config['jwt_secret']);
|
|
|
- $userType = $payload->aud;
|
|
|
- $tokenInfoKey = self::TOKEN_INFO . $userType . ':' . $userId;
|
|
|
$this->cache->remember(self::TOKEN_REVOKE . $payload->jti, time(), $remainingTime);
|
|
|
- // 只有jti匹配才清除token_info
|
|
|
- $tokenInfo = $this->cache->get($tokenInfoKey);
|
|
|
- if ($tokenInfo && ($tokenInfo['jti'] ?? null) === $payload->jti) {
|
|
|
- $this->cache->delete($tokenInfoKey);
|
|
|
- }
|
|
|
+ $this->cache->delete(self::TOKEN_INFO . $payload->aud . ':' . $userId . ':' . $payload->jti);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -73,7 +66,7 @@ class AuthHook
|
|
|
*/
|
|
|
public function getOnlineCount(UserTypeEnum $userType): int
|
|
|
{
|
|
|
- $pattern = $this->cache->getCacheKey(self::TOKEN_INFO . $userType->value . ':*');
|
|
|
+ $pattern = $this->cache->getCacheKey(self::TOKEN_INFO . $userType->value . ':*:');
|
|
|
$keys = $this->cache->handler()->keys($pattern);
|
|
|
return count($keys);
|
|
|
}
|