浏览代码

Remove existing sessions for a user on the same device on login

Bill Thornton 1 年之前
父节点
当前提交
9ea46b9e17
共有 1 个文件被更改,包括 12 次插入6 次删除
  1. 12 6
      Emby.Server.Implementations/Session/SessionManager.cs

+ 12 - 6
Emby.Server.Implementations/Session/SessionManager.cs

@@ -1509,14 +1509,20 @@ namespace Emby.Server.Implementations.Session
                 new DeviceQuery
                 {
                     DeviceId = deviceId,
-                    UserId = user.Id,
-                    Limit = 1
-                }).ConfigureAwait(false)).Items.FirstOrDefault();
+                    UserId = user.Id
+                }).ConfigureAwait(false)).Items;
 
-            if (existing is not null)
+            foreach (var auth in existing)
             {
-                _logger.LogInformation("Reusing existing access token: {Token}", existing.AccessToken);
-                return existing.AccessToken;
+                try
+                {
+                    // Logout any existing sessions for the user on this device
+                    await Logout(auth).ConfigureAwait(false);
+                }
+                catch (Exception ex)
+                {
+                    _logger.LogError(ex, "Error while logging out existing session.");
+                }
             }
 
             _logger.LogInformation("Creating new access token for user {0}", user.Id);