fix(auth): enforce single-session with DB tokenVersion + heartbeat detection
Move single-session invalidation from cache-based token version checks to a database-backed, atomic tokenVersion flow to eliminate concurrent login race conditions. Add a global auth heartbeat (visibility-aware) so kicked sessions are detected within ~10s when the page is visible. Made-with: Cursor
This commit is contained in:
@@ -121,11 +121,20 @@ interface DecodedToken {
|
||||
role: string; // 角色
|
||||
tenantId: string; // 租户ID
|
||||
tenantCode?: string; // 租户Code
|
||||
tokenVersion: number; // 会话版本号(单设备登录互踢)
|
||||
iat: number; // 签发时间
|
||||
exp: number; // 过期时间
|
||||
}
|
||||
```
|
||||
|
||||
### 3.4 单账号互踢(强一致)
|
||||
|
||||
- 后端使用 `platform_schema.users.token_version` 作为会话版本号(数据库强一致)
|
||||
- 每次登录都会原子执行 `token_version = token_version + 1`
|
||||
- Access/Refresh Token 均携带 `tokenVersion`
|
||||
- 鉴权时要求 `tokenVersion === users.token_version`,不一致即判定“已在其他设备登录”
|
||||
- 禁止依赖进程内缓存实现互踢(多实例/并发场景会失效)
|
||||
|
||||
## 4. 检查清单
|
||||
|
||||
### 4.1 新模块开发检查清单
|
||||
|
||||
Reference in New Issue
Block a user