fix(server): 被移除的设备会话轮询判活 —— dev 行不存在应判「失效」而非「有效」(bug)
SessionActive 在设备被 DeleteDevice 删行后 FindByUUID 返回 nil,此前一律 return true (「未知/非本人设备不据此登出」)。结果:被移除的设备轮询 /me/session 永远拿到 active=true → 不登出、不弹框,只表现为数据面凭证被召回→隧道断→客户端误报「节点异常」。 改为:dev==nil(自身 device_id 查无此行,已登录客户端必然注册过 → 只能是被移除)→ return false,让其登出;dev.UserID!=userID(他人 uuid)仍 return true 兜底。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -382,8 +382,14 @@ func (svc *Service) SessionActive(ctx context.Context, userID int64, deviceUUID
|
||||
if err != nil {
|
||||
return false, apierr.ErrInternal
|
||||
}
|
||||
if dev == nil || dev.UserID != userID {
|
||||
return true, nil // 未知 / 非本人设备:不据此登出
|
||||
if dev == nil {
|
||||
// 设备行已不存在 = 本设备被「移除」(DeleteDevice 删行)。已登录的客户端在登录时
|
||||
// 必然注册过自己的设备,轮询自身 device_id 却查无此行,只能是被移除 → 视为会话失效,
|
||||
// 让其登出(否则被移除的设备永远收到 active=true,不退出,只表现为数据面被断→「节点异常」)。
|
||||
return false, nil
|
||||
}
|
||||
if dev.UserID != userID {
|
||||
return true, nil // 非本人设备 uuid:不据此登出(fail-safe)
|
||||
}
|
||||
active, err := svc.sessions.HasActiveSession(ctx, userID, dev.ID)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user