using System.Security.Claims; using Microsoft.AspNetCore.Components.Authorization; using OrdersManagementDataModel.Dtos; namespace OrdersManagement; public class CustomAuthenticationStateProvider : AuthenticationStateProvider { private UserDto? _currentUser; public override Task GetAuthenticationStateAsync() { var identity = _currentUser != null ? new ClaimsIdentity([new Claim(ClaimTypes.Name, _currentUser.Login)], "CustomAuth") : new ClaimsIdentity(); return Task.FromResult(new AuthenticationState(new ClaimsPrincipal(identity))); } public Task MarkUserAsAuthenticated(UserDto? user) { _currentUser = user; NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return Task.CompletedTask; } public void MarkUserAsLoggedOut() { _currentUser = null; NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); } }