Code cleanup
This commit is contained in:
@@ -3,21 +3,14 @@ using Sandbox.Models.ViewModels;
|
|||||||
|
|
||||||
namespace Sandbox.App.Services.AuthService;
|
namespace Sandbox.App.Services.AuthService;
|
||||||
|
|
||||||
public class AuthService : IAuthService
|
public class AuthService(HttpClient httpClient, AuthenticationStateProvider authenticationStateProvider)
|
||||||
|
: IAuthService
|
||||||
{
|
{
|
||||||
private readonly HttpClient _http;
|
private readonly AuthenticationStateProvider _authenticationStateProvider = authenticationStateProvider;
|
||||||
//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)
|
public async Task<ServiceResponse<int>> Register(UserRegister request)
|
||||||
{
|
{
|
||||||
var result = await _http.PostAsJsonAsync("api/auth/register", request);
|
var result = await httpClient.PostAsJsonAsync("api/auth/register", request);
|
||||||
return await result.Content.ReadFromJsonAsync<ServiceResponse<int>>();
|
return await result.Content.ReadFromJsonAsync<ServiceResponse<int>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
@using Sandbox.Models.ViewModels
|
@using Sandbox.Models.ViewModels
|
||||||
|
|
||||||
@inject Sandbox.App.Services.AuthService.IAuthService AuthService
|
@inject Sandbox.App.Services.AuthService.IAuthService AuthService
|
||||||
@* @inject AuthenticationStateProvider AuthenticationStateProvider *@
|
|
||||||
@* @inject NavigationManager NavigationManager *@
|
|
||||||
|
|
||||||
<title>Register</title>
|
<title>Register</title>
|
||||||
|
|
||||||
@@ -52,8 +50,6 @@
|
|||||||
@code {
|
@code {
|
||||||
[SupplyParameterFromForm] private UserRegister user { get; set; }
|
[SupplyParameterFromForm] private UserRegister user { get; set; }
|
||||||
|
|
||||||
//HttpClient _http = new() { BaseAddress = new("https://localhost:7122") };
|
|
||||||
|
|
||||||
private string message = string.Empty;
|
private string message = string.Empty;
|
||||||
private string messageCssClass = string.Empty;
|
private string messageCssClass = string.Empty;
|
||||||
private string errorMessage = string.Empty;
|
private string errorMessage = string.Empty;
|
||||||
@@ -62,8 +58,6 @@
|
|||||||
|
|
||||||
async Task HandleRegistration()
|
async Task HandleRegistration()
|
||||||
{
|
{
|
||||||
// var response = await _http.PostAsJsonAsync("/api/register", user);
|
|
||||||
// var result = await response.Content.ReadFromJsonAsync<ServiceResponse<int>>();
|
|
||||||
var result = await AuthService.Register(user);
|
var result = await AuthService.Register(user);
|
||||||
message = result.Message;
|
message = result.Message;
|
||||||
messageCssClass = result.Success ? "text-success" : "text-danger";
|
messageCssClass = result.Success ? "text-success" : "text-danger";
|
||||||
|
|||||||
@@ -2,7 +2,12 @@
|
|||||||
using Microsoft.AspNetCore.Hosting.Server.Features;
|
using Microsoft.AspNetCore.Hosting.Server.Features;
|
||||||
|
|
||||||
namespace Sandbox;
|
namespace Sandbox;
|
||||||
|
/// <summary>
|
||||||
|
/// Source: https://www.duracellko.net/posts/2020/06/hosting-both-blazor-server-and-webassembly
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="httpClient"></param>
|
||||||
|
/// <param name="server"></param>
|
||||||
|
/// <param name="applicationLifetime"></param>
|
||||||
public class HttpClientSetupService(
|
public class HttpClientSetupService(
|
||||||
HttpClient httpClient,
|
HttpClient httpClient,
|
||||||
IServer server,
|
IServer server,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using Sandbox.Components;
|
|||||||
using Sandbox.Models.ViewModels;
|
using Sandbox.Models.ViewModels;
|
||||||
using Sandbox.Services.AuthService;
|
using Sandbox.Services.AuthService;
|
||||||
using ClientServices = Sandbox.App.Services;
|
using ClientServices = Sandbox.App.Services;
|
||||||
using ServerServices = Sandbox.Services;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user