Applications.razor for applicants
This commit is contained in:
		| @@ -0,0 +1,12 @@ | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider | ||||
| { | ||||
|     public interface IUserDataProvider | ||||
|     { | ||||
|  | ||||
|         public ApplicantModel? GetApplicant(); | ||||
|  | ||||
|         public string? GetCurrentRole(); | ||||
|     } | ||||
| } | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user