Applications.razor for applicants

This commit is contained in:
2024-09-06 21:37:16 +03:00
parent 53d5758527
commit f90a0e7e82
13 changed files with 227 additions and 125 deletions

View File

@@ -0,0 +1,12 @@
using VisaApiClient;
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider
{
public interface IUserDataProvider
{
public ApplicantModel? GetApplicant();
public string? GetCurrentRole();
}
}

View File

@@ -0,0 +1,30 @@
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using VisaApiClient;
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider
{
public class UserDataProvider(Client client) : IUserDataProvider
{
private static readonly JwtSecurityTokenHandler tokenHandler = new ();
public ApplicantModel? GetApplicant()
{
//todo api action
return null;
}
public string? GetCurrentRole()
{
if (client.AuthToken is null)
{
return null;
}
var token = tokenHandler.ReadJwtToken(client.AuthToken.Token);
var role = token.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.Role)?.Value;
return role;
}
}
}