Navmenu related to current authorized user's role

This commit is contained in:
2024-09-12 00:08:22 +03:00
parent 96c70ef0ba
commit 18e02792ec
7 changed files with 50 additions and 15 deletions

View File

@@ -4,9 +4,12 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvide
{
public interface IUserDataProvider
{
public string? CurrentRole { get; }
public Action? OnRoleChanged { get; set; }
public Task<ApplicantModel> GetApplicant();
public string? GetCurrentRole();
public void UpdateCurrentRole();
}
}

View File

@@ -9,16 +9,21 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvide
{
private readonly static JwtSecurityTokenHandler tokenHandler = new();
public string? CurrentRole { get; private set; }
public Action? OnRoleChanged { get; set; }
public async Task<ApplicantModel> GetApplicant()
{
return await client.GetApplicantAsync();
}
public string? GetCurrentRole()
public void UpdateCurrentRole()
{
if (client.AuthToken is null)
{
return null;
CurrentRole = null;
return;
}
var token = tokenHandler.ReadJwtToken(client.AuthToken.Token);
@@ -32,7 +37,11 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvide
default: throw new UnknownRoleException();
}
return role;
if (CurrentRole != role)
{
CurrentRole = role;
OnRoleChanged?.Invoke();
}
}
}
}