diff --git a/src/Server.UI/Components/Fusion/OnlineUsersTracker.razor b/src/Server.UI/Components/Fusion/OnlineUsersTracker.razor index fe79e4f2f..701774f50 100644 --- a/src/Server.UI/Components/Fusion/OnlineUsersTracker.razor +++ b/src/Server.UI/Components/Fusion/OnlineUsersTracker.razor @@ -70,7 +70,9 @@ public override async ValueTask DisposeAsync() { - await OnlineUserTracker.Logout(); + if (!string.IsNullOrEmpty(currentUserId)){ + await OnlineUserTracker.Clear(currentUserId); + } GC.Collect(); } } diff --git a/src/Server.UI/Services/Fusion/IOnlineUserTracker.cs b/src/Server.UI/Services/Fusion/IOnlineUserTracker.cs index 5b7800b3f..9a840adde 100644 --- a/src/Server.UI/Services/Fusion/IOnlineUserTracker.cs +++ b/src/Server.UI/Services/Fusion/IOnlineUserTracker.cs @@ -5,7 +5,6 @@ namespace CleanArchitecture.Blazor.Server.UI.Services.Fusion; public interface IOnlineUserTracker : IComputeService { Task Initial(SessionInfo sessionInfo,CancellationToken cancellationToken = default); - Task Logout(CancellationToken cancellationToken = default); Task Clear(string userId,CancellationToken cancellationToken = default); Task Update(string userId,string userName,string displayName,string profilePictureDataUrl, CancellationToken cancellationToken = default); [ComputeMethod] diff --git a/src/Server.UI/Services/Fusion/OnlineUserTracker.cs b/src/Server.UI/Services/Fusion/OnlineUserTracker.cs index 5ab0f6913..f0c3ccefd 100644 --- a/src/Server.UI/Services/Fusion/OnlineUserTracker.cs +++ b/src/Server.UI/Services/Fusion/OnlineUserTracker.cs @@ -39,23 +39,7 @@ public virtual async Task Initial(SessionInfo sessionInfo, CancellationToken can } } - /// - /// Logs out the current user. - /// - /// The cancellation token. - public virtual async Task Logout(CancellationToken cancellationToken = default) - { - if (Invalidation.IsActive) - return; - var sessionInfo = await GetSessionInfo().ConfigureAwait(false); - var userSessions = _activeUserSessions.Where(s => s.UserId == sessionInfo.UserId).ToList(); - foreach (var session in userSessions) - { - _activeUserSessions = _activeUserSessions.Remove(session); - using var invalidating = Invalidation.Begin(); - _ = await GetOnlineUsers(cancellationToken).ConfigureAwait(false); - } - } + /// /// Clears all sessions for a specific user. @@ -109,25 +93,4 @@ public virtual Task> GetOnlineUsers(CancellationToken cancella return Task.FromResult(_activeUserSessions.ToList()); } - - /// - /// Gets the session information for the current user. - /// - /// The session information. - /// Thrown when the HTTP context is not available. - private Task GetSessionInfo() - { - var httpContext = _httpContextAccessor.HttpContext; - if (httpContext == null) - { - throw new InvalidOperationException("HttpContext is not available."); - } - var httpUser = _httpContextAccessor.HttpContext?.User; - var ipAddress = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress?.ToString(); - var userId = _httpContextAccessor.HttpContext?.User?.GetUserId(); - var userName = _httpContextAccessor.HttpContext?.User?.GetUserName(); - var displayName = _httpContextAccessor.HttpContext?.User?.GetDisplayName(); - var tenantId = _httpContextAccessor.HttpContext?.User?.GetTenantId(); - return Task.FromResult(new SessionInfo(userId, userName, displayName, ipAddress, tenantId, "", UserPresence.Available)); - } }