Still invalid submit. Tried to add an API route to call service through http.

This commit is contained in:
2026-01-27 22:13:09 +01:00
parent b3182b3ae7
commit 803a9f86e1
2 changed files with 7 additions and 3 deletions

View File

@@ -1,10 +1,8 @@
@page "/register" @page "/register"
@using Sandbox.Models.ViewModels @using Sandbox.Models.ViewModels
@using Sandbox.Services.AuthService
@* @inject AuthenticationStateProvider AuthenticationStateProvider *@ @* @inject AuthenticationStateProvider AuthenticationStateProvider *@
@* @inject NavigationManager NavigationManager *@ @* @inject NavigationManager NavigationManager *@
@inject IAuthService AuthService
<title>Register</title> <title>Register</title>
@@ -48,6 +46,7 @@
@code { @code {
UserRegister user = new(); UserRegister user = new();
HttpClient _http = new();
private string message = string.Empty; private string message = string.Empty;
private string messageCssClass = string.Empty; private string messageCssClass = string.Empty;
@@ -55,7 +54,8 @@
async void HandleRegistration() async void HandleRegistration()
{ {
var result = await AuthService.Register(user.Email, user.Password); var response = await _http.PostAsJsonAsync("api/auth/register", user);
var result = await response.Content.ReadFromJsonAsync<ServiceResponse<int>>();
message = result.Message; message = result.Message;
messageCssClass = result.Success ? "text-success" : "text-danger"; messageCssClass = result.Success ? "text-success" : "text-danger";
} }

View File

@@ -1,4 +1,5 @@
using Sandbox.Components; using Sandbox.Components;
using Sandbox.Models.ViewModels;
using Sandbox.Services.AuthService; using Sandbox.Services.AuthService;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@@ -23,6 +24,9 @@ app.UseHttpsRedirection();
app.UseAntiforgery(); app.UseAntiforgery();
app.MapPost("/register", async (UserRegister request, IAuthService authService) =>
await authService.Register(request.Email, request.Password));
app.MapStaticAssets(); app.MapStaticAssets();
app.MapRazorComponents<App>() app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode(); .AddInteractiveServerRenderMode();