Auth and error handling components
This commit is contained in:
		| @@ -1,6 +1,10 @@ | ||||
| @page "/" | ||||
| @using System.Net | ||||
| @using BlazorWebAssemblyVisaApiClient.Components.Auth | ||||
| @using VisaApiClient | ||||
| @using BlazorWebAssemblyVisaApiClient.Components.FormComponents.Applicants | ||||
| @using BlazorWebAssemblyVisaApiClient.Components | ||||
| @inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase | ||||
|  | ||||
| <PageTitle>Authentication</PageTitle> | ||||
|  | ||||
| @@ -13,30 +17,17 @@ | ||||
|         <input class="btn-outline-primary rounded" type="submit" value="Login"/> | ||||
|         or | ||||
|         <NavLink href="register">Register</NavLink > | ||||
|         <p>@loginResult</p> | ||||
|         <Status><AuthComponent @ref="auth"/></Status> | ||||
|     </EditForm> | ||||
| </div> | ||||
|  | ||||
| @code | ||||
| { | ||||
|     private AuthData loginData = new(); | ||||
|     private string loginResult = string.Empty; | ||||
|  | ||||
|     [Inject] private Client Client { get; set; } = null!; | ||||
|     private AuthComponent auth = null!; | ||||
|  | ||||
|     private async Task TryLogin() | ||||
|     { | ||||
|         loginResult = "Wait..."; | ||||
|         StateHasChanged(); | ||||
|         try | ||||
|         { | ||||
|             var token = await Client.LoginAsync(loginData.Email, loginData.Password); | ||||
|             Client.SetAuthToken(token); | ||||
|             loginResult = "Logged in successfully."; | ||||
|         } | ||||
|         catch (ApiException<ProblemDetails> e) | ||||
|         { | ||||
|             loginResult = e.Result.Detail!; | ||||
|         } | ||||
|         await auth.TryAuthorize(loginData); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user