diff --git a/WebApp/Components/App.razor b/WebApp/Components/App.razor index 32271cd..63d504d 100644 --- a/WebApp/Components/App.razor +++ b/WebApp/Components/App.razor @@ -26,6 +26,7 @@ + diff --git a/WebApp/Components/Features/Authentication/Login.razor b/WebApp/Components/Features/Authentication/Login.razor index 2add330..2295c69 100644 --- a/WebApp/Components/Features/Authentication/Login.razor +++ b/WebApp/Components/Features/Authentication/Login.razor @@ -134,7 +134,7 @@ if (e.Key == "Enter") { // Blur the active element to ensure MudTextField bindings update - await JS.InvokeVoidAsync("eval", "document.activeElement.blur()"); + await JS.InvokeVoidAsync("tsaLogin.blurActiveElement"); // Small delay to allow bindings to process await Task.Delay(50); @@ -146,14 +146,11 @@ private async Task HandleFormSubmit() { - // Update hidden inputs with current model values, then submit the form - var returnUrlValue = string.IsNullOrEmpty(_returnUrl) ? "" : System.Text.Json.JsonSerializer.Serialize(_returnUrl); - await JS.InvokeVoidAsync("eval", $@" - document.getElementById('emailInput').value = {System.Text.Json.JsonSerializer.Serialize(_loginModel.Email)}; - document.getElementById('passwordInput').value = {System.Text.Json.JsonSerializer.Serialize(_loginModel.Password)}; - document.getElementById('rememberMeInput').value = '{_loginModel.RememberMe.ToString().ToLower()}'; - document.getElementById('returnUrlInput').value = {returnUrlValue}; - document.getElementById('loginForm').submit(); - "); + await JS.InvokeVoidAsync( + "tsaLogin.submitForm", + _loginModel.Email ?? string.Empty, + _loginModel.Password ?? string.Empty, + _loginModel.RememberMe, + _returnUrl ?? string.Empty); } } diff --git a/WebApp/wwwroot/js/login.js b/WebApp/wwwroot/js/login.js new file mode 100644 index 0000000..7ab33ff --- /dev/null +++ b/WebApp/wwwroot/js/login.js @@ -0,0 +1,30 @@ +window.tsaLogin = { + /** + * Copies Blazor-bound credentials into the classic form fields and submits. + * Avoids building JS via string eval (empty returnUrl previously produced ".value = ;"). + */ + submitForm: function (email, password, rememberMe, returnUrl) { + var emailInput = document.getElementById('emailInput'); + var passwordInput = document.getElementById('passwordInput'); + var rememberMeInput = document.getElementById('rememberMeInput'); + var returnUrlInput = document.getElementById('returnUrlInput'); + var form = document.getElementById('loginForm'); + + if (!emailInput || !passwordInput || !rememberMeInput || !returnUrlInput || !form) { + console.error('tsaLogin.submitForm: login form elements not found'); + return; + } + + emailInput.value = email ?? ''; + passwordInput.value = password ?? ''; + rememberMeInput.value = rememberMe ? 'true' : 'false'; + returnUrlInput.value = returnUrl ?? ''; + form.submit(); + }, + + blurActiveElement: function () { + if (document.activeElement && typeof document.activeElement.blur === 'function') { + document.activeElement.blur(); + } + } +};