Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Auto submit login form when 2fa code is entered (#495)

Leendert de Borstcd465785767f
diff --git a/src/AliasVault.Client/Auth/Pages/Login.razor b/src/AliasVault.Client/Auth/Pages/Login.razor
index ef507f00e..bc9099ec0 100644
--- a/src/AliasVault.Client/Auth/Pages/Login.razor
+++ b/src/AliasVault.Client/Auth/Pages/Login.razor
@@ -24,7 +24,11 @@
<DataAnnotationsValidator/>
<div>
<label for="two-factor-code" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Authenticator code</label>
- <InputNumber @bind-Value="_loginModel2Fa.TwoFactorCode" id="two-factor-code" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" autocomplete="off"/>
+ <InputNumber @bind-Value="_loginModel2Fa.TwoFactorCode"
+ id="two-factor-code"
+ @oninput="OnTwoFactorCodeInput"
+ class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
+ autocomplete="off"/>
<ValidationMessage For="() => _loginModel2Fa.TwoFactorCode" class="text-red-600 dark:text-red-400 text-sm mt-1"/>
</div>
<div class="flex items-start">
@@ -417,4 +421,24 @@ else
return [];
}
+
+ /// <summary>
+ /// Auto submit the 2FA code when 6 digits are entered.
+ /// </summary>
+ /// <param name="e"></param>
+ private async Task OnTwoFactorCodeInput(ChangeEventArgs e)
+ {
+ if (e.Value?.ToString()?.Length >= 6)
+ {
+ // Update the blazor model with the current value.
+ _loginModel2Fa.TwoFactorCode = int.Parse(e.Value.ToString()!);
+
+ // Submit the form.
+ await Handle2Fa();
+ }
+ else
+ {
+ _serverValidationErrors.Clear();
+ }
+ }
}
diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/TwoFactorAuthTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/TwoFactorAuthTests.cs
index c5af88337..a73eec39f 100644
--- a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/TwoFactorAuthTests.cs
+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard3/TwoFactorAuthTests.cs
@@ -56,12 +56,11 @@ public class TwoFactorAuthTests : TwoFactorAuthBase
var prompt = await Page.TextContentAsync("label:has-text('Authenticator code')");
Assert.That(prompt, Does.Contain("Authenticator code"), "No 2FA code prompt displayed.");
- // Fill in the 2FA code and submit the form.
+ // Fill in the 2FA code.
var totpField = await WaitForAndGetElement("input[id='two-factor-code']");
await totpField.FillAsync(totpCode);
- var submitButton = Page.Locator("button[type='submit']");
- await submitButton.ClickAsync();
+ // Form should auto-submit after filling in the 6-digit code.
// Check if we get redirected to the index page.
await WaitForUrlAsync("welcome**", WelcomeMessage);