It works: client service + server service + utility service to know server uri when app is running
This commit is contained in:
40
App.Services/AuthService/AuthService.cs
Normal file
40
App.Services/AuthService/AuthService.cs
Normal 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;
|
||||
// }
|
||||
}
|
||||
11
App.Services/AuthService/IAuthService.cs
Normal file
11
App.Services/AuthService/IAuthService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Sandbox.Models.ViewModels;
|
||||
|
||||
namespace Sandbox.App.Services.AuthService;
|
||||
|
||||
public interface IAuthService
|
||||
{
|
||||
Task<ServiceResponse<int>> Register(UserRegister request);
|
||||
// Task<ServiceResponse<string>> Login(UserLogin request);
|
||||
// Task<ServiceResponse<bool>> ChangePassword(UserChangePassword request);
|
||||
// Task<bool> IsUserAuthenticated();
|
||||
}
|
||||
Reference in New Issue
Block a user