It works: client service + server service + utility service to know server uri when app is running

This commit is contained in:
2026-01-28 22:34:01 +01:00
parent a74065f768
commit fc8d59ae12
7 changed files with 125 additions and 9 deletions

View File

@@ -0,0 +1,40 @@
using Microsoft.AspNetCore.Components.Authorization;
using Sandbox.Models.ViewModels;
namespace Sandbox.App.Services.AuthService;
public class AuthService : IAuthService
{
private readonly HttpClient _http;
//private readonly AuthenticationStateProvider _authenticationStateProvider;
// public AuthService(HttpClient httpClient, AuthenticationStateProvider authenticationStateProvider)
public AuthService(HttpClient httpClient)
{
_http = httpClient;
//_authenticationStateProvider = authenticationStateProvider;
}
public async Task<ServiceResponse<int>> Register(UserRegister request)
{
var result = await _http.PostAsJsonAsync("api/auth/register", request);
return await result.Content.ReadFromJsonAsync<ServiceResponse<int>>();
}
// public async Task<ServiceResponse<string>> Login(UserLogin request)
// {
// var result = await _http.PostAsJsonAsync("api/auth/login", request);
// return await result.Content.ReadFromJsonAsync<ServiceResponse<string>>();
// }
//
// public async Task<ServiceResponse<bool>> ChangePassword(UserChangePassword request)
// {
// var result = await _http.PostAsJsonAsync("api/auth/change-password", request.Password);
// return await result.Content.ReadFromJsonAsync<ServiceResponse<bool>>();
// }
// public async Task<bool> IsUserAuthenticated()
// {
// return (await _authenticationStateProvider.GetAuthenticationStateAsync()).User.Identity.IsAuthenticated;
// }
}