using GameIdeas.BlazorApp.Services; 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, AuthenticationStateProvider stateProvider) : IAuthGateway { public async Task Login(UserDto userDto) { try { var token = await httpClient.PostAsync(Endpoints.Auth.Login, userDto); await ((JwtAuthenticationStateProvider)stateProvider).NotifyUserAuthenticationAsync(token!.Token!); return true; } catch (Exception) { throw new AuthenticationUserException(ResourcesKey.UserLoginFailed); } } public async Task Logout() { try { await ((JwtAuthenticationStateProvider)stateProvider).NotifyUserLogoutAsync(); } catch (Exception) { throw new AuthenticationUserException(ResourcesKey.UserLogoutFailed); } } }