From 5f39f2e0633fd717f42005ce7c1905eaaab9c696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Jasi=C5=84ski?= Date: Sun, 10 May 2026 20:17:02 +0200 Subject: [PATCH] fix: implement server-side logout by clearing token via INativeStorageService --- .../Services/ServerIdentityService.cs | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/NexusReader.Web.New/Services/ServerIdentityService.cs b/src/NexusReader.Web.New/Services/ServerIdentityService.cs index bac61e2..9b52d88 100644 --- a/src/NexusReader.Web.New/Services/ServerIdentityService.cs +++ b/src/NexusReader.Web.New/Services/ServerIdentityService.cs @@ -7,7 +7,9 @@ using NexusReader.Data.Persistence; using NexusReader.Domain.Entities; using NexusReader.Application.Queries.User; using MediatR; +using NexusReader.UI.Shared.Constants; using NexusReader.UI.Shared.Services; +using NexusReader.Application.Abstractions.Services; namespace NexusReader.Web.New.Services; @@ -16,24 +18,50 @@ public class ServerIdentityService : IIdentityService private readonly UserManager _userManager; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IMediator _mediator; + private readonly INativeStorageService _storageService; public event Func? OnStateInvalidated; public ServerIdentityService( UserManager userManager, IHttpContextAccessor httpContextAccessor, - IMediator mediator) + IMediator mediator, + INativeStorageService storageService) { _userManager = userManager; _httpContextAccessor = httpContextAccessor; _mediator = mediator; + _storageService = storageService; } public Task LoginAsync(string email, string password, bool rememberMe = false) => throw new NotSupportedException("Use standard Identity endpoints for login on server."); - public Task LogoutAsync() - => throw new NotSupportedException("Use standard Identity endpoints for logout on server."); + public async Task LogoutAsync() + { + try + { + // Clear storage if available (Interactive Server mode) + try + { + await _storageService.SaveSecureString(StorageKeys.AuthToken, ""); + await _storageService.SaveSecureString(StorageKeys.RefreshToken, ""); + await _storageService.SaveSecureString(StorageKeys.UserEmail, ""); + await _storageService.SaveSecureString(StorageKeys.UserTenant, ""); + } + catch + { + // Ignore errors during prerendering where JS interop isn't available + } + + if (OnStateInvalidated != null) await OnStateInvalidated.Invoke(); + return Result.Ok(); + } + catch (Exception ex) + { + return Result.Fail(new Error("Logout failed.").CausedBy(ex)); + } + } public Task RegisterAsync(string email, string password) => throw new NotSupportedException("Use standard Identity endpoints for registration on server.");