Using this interaction mode, I cannot authenticate in any way. The last thing I tried was sending a request via HttpClient. The cookie is generated and added in the browser, but I still remain unauthorized.
Please tell me what to do. Other mode of operation Blazor, I am not interested. There at validation of data, there is a reloading of the page, I do not need it. Thank you.
Login.razor:
<div class="row"><h3>Login</h3><div class="section-description contact-form"><EditForm Model="@Model" OnValidSubmit="Authenticate"><label class="errorMessage" style="display:@Display">@ErrorMessage</label><DataAnnotationsValidator /><div class="text-left"><ValidationMessage For="() => Model.Email" class="errorMessage" /><label for="Email" class="form-label">Email</label><InputText @bind-Value="Model.Email" class="form-control" /></div><div class="text-left"><ValidationMessage For="() => Model.Password" class="errorMessage" /><label for="Password" class="form-label">Password</label><InputText type="Password" @bind-Value="Model.Password" class="form-control" /></div><div class="box"><button class="btn button-game" type="submit"><span class="button-game-bg-left"></span><span class="button-game-bg-mid"><span>Enter</span></span><span class="button-game-bg-right"></span></button></div></EditForm></div></div>@code { protected override void OnInitialized() { var httpContext = HttpContextAccessor.HttpContext; if (httpContext.User.Identity.IsAuthenticated) { httpContext.Response.Redirect("/lobby"); } } [SupplyParameterFromForm] LoginViewModel Model { get; set; } = new(); async Task Authenticate() { HttpClient httpClient = ClientFactory.CreateClient(); var response = await httpClient.PostAsJsonAsync("https://localhost:7051/api/auth", Model); if (response.IsSuccessStatusCode) { HttpContextAccessor.HttpContext.Response.Redirect("/Lobby"); } else { // Handle error response } }}AccountController:
public class AccountController : Controller { private readonly SignInManager<User> _signInManager; public AccountController(SignInManager<User> signInManager) { _signInManager = signInManager; } [Route("api/auth")] [HttpPost] public async Task<IActionResult> Login([FromBody] LoginViewModel model) { var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false); if (result.Succeeded) { return Ok(); } else { return BadRequest("Not valid password"); } } }Tried everything.
Going to see a solution with the mode of operation:@rendermode RenderMode.InteractiveServer