初始化

缺陷:主题配色需要优化整体的同风格
This commit is contained in:
2026-08-14 23:21:21 +08:00
parent 6e2769c528
commit bcf54c2727
152 changed files with 13521 additions and 141 deletions

View File

@@ -122,6 +122,44 @@ class JWTService
return $this->generateToken((array)$decoded->data);
}
/**
* 解析已过期但签名有效的 token
*
* 续签场景下 token 必然已经过期,正常 decode 会直接抛 ExpiredException。
* 这里临时放宽 leeway exp 校验通过,签名与 Redis 会话仍然照常校验,
* 所以过期的 token 依旧不能凭空续签——会话被登出或超过宽限期就必须重新登录。
*
* @param int $leeway 允许的过期宽限秒数
*/
public function parseExpiringToken(int $leeway): ?object
{
$token = request()->bearerToken();
if (empty($token)) {
return null;
}
$origin = JWT::$leeway;
JWT::$leeway = max(0, $leeway);
try {
return JWT::decode($token, new Key($this->secretKey, 'HS256'));
} catch (Exception $e) {
return null;
} finally {
JWT::$leeway = $origin;
}
}
/**
* 作废某个用户的登录态:删掉 Redis 会话,手里的 token 立即失效
* getUserInfo 拿不到会话就会 notAuth所以不需要维护黑名单
*/
public function revoke(int $userId): bool
{
if ($userId <= 0) {
return false;
}
return RedisService::getInstance()->init(config('nl.redis.jwt'))->del($userId);
}
}