@page "/account/login" @layout AuthenticationLayout @using Indotalent.Shared.Consts @using Microsoft.JSInterop @using Indotalent.Infrastructure.Authentication.Identity @using Microsoft.Extensions.Options @inject IJSRuntime JSRuntime @inject IOptions IdentityOptions @inject NavigationManager Navigation @inject ISnackbar Snackbar Sign In - @GlobalConsts.AppInitial
Email Address
Password Forgot password?
@if (isProcessing) { Signing in... } else { Sign In } @if (IdentityOptions.Value.SsoFirebase.IsUsed) {
Or continue with
Sign in with Google }
Don't have an account? Create one
@code { private MudForm form = default!; private bool success; private bool isProcessing; private bool showPassword; private bool rememberMe; private LoginModel model = new(); private async Task ValidateForm(EditContext context) => await Task.FromResult(true); private async Task HandleLogin() { await form.Validate(); if (!success) return; isProcessing = true; StateHasChanged(); var result = await JSRuntime.InvokeAsync("apiAccountSignIn", model.Email, model.Password, rememberMe); ProcessLoginResult(result); } private async Task HandleFirebaseGoogleLogin() { isProcessing = true; StateHasChanged(); var firebaseUser = await JSRuntime.InvokeAsync("signInWithGoogle"); if (firebaseUser == null || string.IsNullOrEmpty(firebaseUser.Email)) { Snackbar.Add("Google Sign-In failed or cancelled.", Severity.Error); isProcessing = false; return; } var checkResult = await JSRuntime.InvokeAsync("apiCheckActiveUser", firebaseUser.Email); bool openForPublic = IdentityOptions.Value.SsoFirebase.OpenForPublic; if (checkResult.Exists) { if (checkResult.IsActive) { await ExecuteSsoSignIn(firebaseUser.Email); } else { Snackbar.Add("Account is registered but not active.", Severity.Warning); isProcessing = false; } } else { var registerResult = await JSRuntime.InvokeAsync( "apiAccountSignUpSso", firebaseUser.Email, firebaseUser.Email, openForPublic ); if (registerResult.Status == 200) { if (openForPublic) { await ExecuteSsoSignIn(firebaseUser.Email); } else { Snackbar.Add("Registration successful. Please wait for admin approval.", Severity.Info); isProcessing = false; } } else { Snackbar.Add("Failed to auto-register account.", Severity.Error); isProcessing = false; } } } private async Task ExecuteSsoSignIn(string email) { var result = await JSRuntime.InvokeAsync("apiAccountSsoSignIn", email); ProcessLoginResult(result); } private void ProcessLoginResult(ApiJSRuntimeResponse result) { if (result.Status == 200) { Snackbar.Add(result.Title ?? "Login successful!", Severity.Success); Task.Run(async () => { await Task.Delay(500); Navigation.NavigateTo("/account/tenant-selection", forceLoad: true); }); } else { Snackbar.Add(result.Title ?? "Sign in failed.", Severity.Error); isProcessing = false; } StateHasChanged(); } private class ApiJSRuntimeResponse { public int? Status { get; set; } public string? Title { get; set; } public string? Message { get; set; } } private class FirebaseUserResponse { public string? Email { get; set; } } private class ActiveCheckResponse { public bool Exists { get; set; } public bool IsActive { get; set; } } private class LoginModel { public string Email { get; set; } = ""; public string Password { get; set; } = ""; } }