Refactor: Web Consolidation and Identity Stabilization #40
@@ -7,7 +7,9 @@ using NexusReader.Data.Persistence;
|
|||||||
using NexusReader.Domain.Entities;
|
using NexusReader.Domain.Entities;
|
||||||
using NexusReader.Application.Queries.User;
|
using NexusReader.Application.Queries.User;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
|
using NexusReader.UI.Shared.Constants;
|
||||||
using NexusReader.UI.Shared.Services;
|
using NexusReader.UI.Shared.Services;
|
||||||
|
using NexusReader.Application.Abstractions.Services;
|
||||||
|
|
||||||
namespace NexusReader.Web.New.Services;
|
namespace NexusReader.Web.New.Services;
|
||||||
|
|
||||||
@@ -16,24 +18,50 @@ public class ServerIdentityService : IIdentityService
|
|||||||
private readonly UserManager<NexusUser> _userManager;
|
private readonly UserManager<NexusUser> _userManager;
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
private readonly IMediator _mediator;
|
private readonly IMediator _mediator;
|
||||||
|
private readonly INativeStorageService _storageService;
|
||||||
|
|
||||||
public event Func<Task>? OnStateInvalidated;
|
public event Func<Task>? OnStateInvalidated;
|
||||||
|
|
||||||
public ServerIdentityService(
|
public ServerIdentityService(
|
||||||
UserManager<NexusUser> userManager,
|
UserManager<NexusUser> userManager,
|
||||||
IHttpContextAccessor httpContextAccessor,
|
IHttpContextAccessor httpContextAccessor,
|
||||||
IMediator mediator)
|
IMediator mediator,
|
||||||
|
INativeStorageService storageService)
|
||||||
{
|
{
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
_mediator = mediator;
|
_mediator = mediator;
|
||||||
|
_storageService = storageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Result> LoginAsync(string email, string password, bool rememberMe = false)
|
public Task<Result> LoginAsync(string email, string password, bool rememberMe = false)
|
||||||
=> throw new NotSupportedException("Use standard Identity endpoints for login on server.");
|
=> throw new NotSupportedException("Use standard Identity endpoints for login on server.");
|
||||||
|
|
||||||
public Task<Result> LogoutAsync()
|
public async Task<Result> LogoutAsync()
|
||||||
=> throw new NotSupportedException("Use standard Identity endpoints for logout on server.");
|
{
|
||||||
|
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)
|
public Task<Result> RegisterAsync(string email, string password)
|
||||||
=> throw new NotSupportedException("Use standard Identity endpoints for registration on server.");
|
=> throw new NotSupportedException("Use standard Identity endpoints for registration on server.");
|
||||||
|
|||||||
Reference in New Issue
Block a user