fix: 踢出用户时清除所有 session,确保旧 token 立即失效
Build docker and publish / build (20.15.1) (push) Successful in 7m43s
Build docker and publish / build (20.15.1) (push) Successful in 7m43s
- kickOfflineByUserDeviceLogic: 管理员踢设备后新增 clearAllSessions, 之前只清单个 WebSocket session,用户可用旧 token 继续访问 - unbindDeviceLogic: 家庭成员被踢时增加踢设备+清 session; 补全 session detail key 清理 Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
@@ -208,7 +208,7 @@ func (l *UnbindDeviceLogic) logoutUnbind(userInfo *user.User, device *user.Devic
|
||||
// 7. 清除该用户所有 session(旧 token 全部失效)
|
||||
l.clearAllSessions(userInfo.Id)
|
||||
|
||||
// 8. 清理受影响的家庭成员缓存(家庭解散/转移后成员需感知变化)
|
||||
// 8. 清理受影响的家庭成员缓存 + 踢设备 + 清 session
|
||||
for _, memberID := range familyMemberIDs {
|
||||
if memberUser, findErr := l.svcCtx.UserModel.FindOne(l.ctx, memberID); findErr == nil {
|
||||
if clearErr := l.svcCtx.UserModel.ClearUserCache(l.ctx, memberUser); clearErr != nil {
|
||||
@@ -218,6 +218,19 @@ func (l *UnbindDeviceLogic) logoutUnbind(userInfo *user.User, device *user.Devic
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 踢该成员的所有在线设备
|
||||
var memberDevices []user.Device
|
||||
l.svcCtx.DB.WithContext(l.ctx).
|
||||
Model(&user.Device{}).
|
||||
Where("user_id = ?", memberID).
|
||||
Find(&memberDevices)
|
||||
for _, d := range memberDevices {
|
||||
l.svcCtx.DeviceManager.KickDevice(d.UserId, d.Identifier)
|
||||
}
|
||||
|
||||
// 清除该成员所有 session,确保旧 token 失效
|
||||
l.clearAllSessions(memberID)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -268,6 +281,7 @@ func (l *UnbindDeviceLogic) clearAllSessions(userId int64) {
|
||||
continue
|
||||
}
|
||||
pipe.Del(l.ctx, fmt.Sprintf("%v:%v", config.SessionIdKey, sessionID))
|
||||
pipe.Del(l.ctx, fmt.Sprintf("%s:detail:%s", config.SessionIdKey, sessionID))
|
||||
}
|
||||
pipe.Del(l.ctx, sessionsKey)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user