Refactor: Web Consolidation and Identity Stabilization #40
@@ -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<NexusUser> _userManager;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly INativeStorageService _storageService;
|
||||
|
||||
public event Func<Task>? OnStateInvalidated;
|
||||
|
||||
public ServerIdentityService(
|
||||
UserManager<NexusUser> userManager,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
IMediator mediator)
|
||||
IMediator mediator,
|
||||
INativeStorageService storageService)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_mediator = mediator;
|
||||
_storageService = storageService;
|
||||
}
|
||||
|
||||
public Task<Result> LoginAsync(string email, string password, bool rememberMe = false)
|
||||
=> throw new NotSupportedException("Use standard Identity endpoints for login on server.");
|
||||
|
||||
public Task<Result> LogoutAsync()
|
||||
=> throw new NotSupportedException("Use standard Identity endpoints for logout on server.");
|
||||
public async Task<Result> 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<Result> RegisterAsync(string email, string password)
|
||||
=> throw new NotSupportedException("Use standard Identity endpoints for registration on server.");
|
||||
|
||||
Reference in New Issue
Block a user