From a01355aeccd5c7292b90d817fe415d4dcc229cd1 Mon Sep 17 00:00:00 2001 From: hailin Date: Thu, 5 Mar 2026 21:16:01 -0800 Subject: [PATCH] =?UTF-8?q?fix(presence-service):=20JWT=20guard=20?= =?UTF-8?q?=E5=90=91=E5=90=8E=E5=85=BC=E5=AE=B9=E6=97=A0=20type=20?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E7=9A=84=E6=97=A7=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新 token 含 type:'access',旧 token 无 type 字段。 改为:只有 type 字段存在且不为 'access' 时才拒绝, 避免已登录用户因旧 token 格式导致心跳永久 401。 Co-Authored-By: Claude Sonnet 4.6 --- .../presence-service/src/shared/guards/jwt-auth.guard.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/services/presence-service/src/shared/guards/jwt-auth.guard.ts b/backend/services/presence-service/src/shared/guards/jwt-auth.guard.ts index 761cdfb7..8d4b0a2e 100644 --- a/backend/services/presence-service/src/shared/guards/jwt-auth.guard.ts +++ b/backend/services/presence-service/src/shared/guards/jwt-auth.guard.ts @@ -23,7 +23,8 @@ export class JwtAuthGuard implements CanActivate { try { const payload = await this.jwtService.verifyAsync(token); - if (payload.type !== 'access') throw new UnauthorizedException('无效的令牌类型'); + // 兼容旧 token(无 type 字段)和新 token(type: 'access') + if (payload.type && payload.type !== 'access') throw new UnauthorizedException('无效的令牌类型'); request.user = { userId: payload.userId, accountSequence: payload.accountSequence,