shopping-assistant-web-client/ShoppingAssistantWebClient.Web/Pages/Login.razor.cs
2023-12-19 23:22:15 +00:00

44 lines
1.0 KiB
C#

using Microsoft.AspNetCore.Components;
using ShoppingAssistantWebClient.Web.Network;
using ShoppingAssistantWebClient.Web.Models.Input;
namespace ShoppingAssistantWebClient.Web.Pages;
public partial class Login : ComponentBase
{
[Inject]
NavigationManager NavigationManager { get; set; }
[Inject]
private AuthenticationService _authenticationService { get; set; }
private string errorMessage = "";
private void RedirectToNewChat() {
var url = $"/";
NavigationManager.NavigateTo(url);
}
public async Task LoginUser(LoginInputModel login) {
if (login.IsEmailOrPhoneProvided)
{
try
{
await _authenticationService.LoginAsync(login);
RedirectToNewChat();
}
catch (Exception ex)
{
errorMessage = "Login failed. Please try again.";
}
}
else
{
errorMessage = "Please provide an email or phone number.";
}
}
}