diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/Component.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/Component.razor new file mode 100644 index 0000000..e69de29 diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/Components/Login.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/Components/Login.razor.cs index 6d73a76..6d8a405 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/Components/Login.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/Components/Login.razor.cs @@ -1,10 +1,14 @@ +using GameIdeas.BlazorApp.Pages.User.Gateways; using GameIdeas.Shared.Dto; +using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Forms; namespace GameIdeas.BlazorApp.Pages.User.Components; public partial class Login { + [Parameter] public IAuthGateway AuthGateway { get; set; } = default!; + private EditContext? EditContext; private UserDto UserDto = new(); private bool IsLoading = false; @@ -21,9 +25,19 @@ public partial class Login return; } - IsLoading = true; - await Task.Delay(TimeSpan.FromSeconds(5)); - IsLoading = false; + try + { + IsLoading = true; + await AuthGateway.Login(UserDto); + } + catch (Exception) + { + throw; + } + finally + { + IsLoading = false; + StateHasChanged(); + } } - } \ No newline at end of file diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/Gateways/AuthGateway.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/Gateways/AuthGateway.cs index f19366e..ea2de5c 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/Gateways/AuthGateway.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/Gateways/AuthGateway.cs @@ -3,18 +3,19 @@ using GameIdeas.BlazorApp.Shared.Constants; using GameIdeas.BlazorApp.Shared.Exceptions; using GameIdeas.Resources; using GameIdeas.Shared.Dto; +using Microsoft.AspNetCore.Components.Authorization; namespace GameIdeas.BlazorApp.Pages.User.Gateways; public class AuthGateway(IHttpClientService httpClient, - JwtAuthenticationStateProvider stateProvider) : IAuthGateway + AuthenticationStateProvider stateProvider) : IAuthGateway { public async Task Login(UserDto userDto) { try { var token = await httpClient.PostAsync(Endpoints.Auth.Login, userDto); - await stateProvider.NotifyUserAuthenticationAsync(token!.Token!); + await ((JwtAuthenticationStateProvider)stateProvider).NotifyUserAuthenticationAsync(token!.Token!); return true; } catch (Exception) @@ -27,7 +28,7 @@ public class AuthGateway(IHttpClientService httpClient, { try { - await stateProvider.NotifyUserLogoutAsync(); + await ((JwtAuthenticationStateProvider)stateProvider).NotifyUserLogoutAsync(); } catch (Exception) { diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/UserMenu.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/UserMenu.razor index cd46546..b069564 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/UserMenu.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/User/UserMenu.razor @@ -1,5 +1,8 @@ -@using GameIdeas.BlazorApp.Shared.Components.BackdropFilter +@using GameIdeas.BlazorApp.Pages.User.Components +@using GameIdeas.BlazorApp.Shared.Components.BackdropFilter @using GameIdeas.BlazorApp.Shared.Constants +@using GameIdeas.Shared.Constants +@using Microsoft.AspNetCore.Components.Authorization