Skip to content

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

Tweak TOTP add flow (#1404)

Leendert de Borst063a26cdb5bb
diff --git a/apps/server/AliasVault.Client/Main/Components/TotpCodes/TotpCodes.razor b/apps/server/AliasVault.Client/Main/Components/TotpCodes/TotpCodes.razor
index 4a1ef1c74..a20c3d34b 100644
--- a/apps/server/AliasVault.Client/Main/Components/TotpCodes/TotpCodes.razor
+++ b/apps/server/AliasVault.Client/Main/Components/TotpCodes/TotpCodes.razor
@@ -30,27 +30,23 @@
</button>
}
- @if ((TotpCodeList.Count == 0 || TotpCodeList.All(t => t.IsDeleted)) && !IsAddFormVisible)
- {
- <div class="flex flex-col justify-center">
- <p class="text-gray-500 dark:text-gray-400"><a @onclick="ShowAddForm" id="add-totp-code" href="javascript:void(0)" class="text-blue-600 hover:text-blue-800 dark:text-blue-500 dark:hover:text-blue-400">@Localizer["AddTotpCodeDescription"]</a></p>
- </div>
- }
- else
- {
- @if (IsAddFormVisible)
+ @* Always show add form or existing codes - no empty state *@
+ @if (IsAddFormVisible)
{
<div class="p-4 mb-4 bg-gray-50 border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600">
<EditForm Model="@NewTotpCode" OnValidSubmit="AddTotpCode">
<DataAnnotationsValidator />
<div class="flex justify-between items-center mb-4">
<h4 class="text-lg font-medium text-gray-900 dark:text-white">@Localizer["AddTotpCodeModalTitle"]</h4>
- <button @onclick="HideAddForm" type="button" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white">
- <svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
- <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
- </svg>
- <span class="sr-only">@Localizer["CloseFormButton"]</span>
- </button>
+ @if (HasExistingCodes)
+ {
+ <button @onclick="HideAddForm" type="button" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white">
+ <svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
+ <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
+ </svg>
+ <span class="sr-only">@Localizer["CloseFormButton"]</span>
+ </button>
+ }
</div>
<p class="mb-4 text-sm text-gray-500 dark:text-gray-400">@Localizer["TotpInstructions"]</p>
<div class="mb-4">
@@ -94,7 +90,6 @@
</div>
}
</div>
- }
</div>
@code {
@@ -130,6 +125,11 @@
private TotpCodeEdit NewTotpCode { get; set; } = new();
private List<Guid> OriginalTotpCodeIds { get; set; } = [];
+ /// <summary>
+ /// Returns true if there are existing (non-deleted) TOTP codes.
+ /// </summary>
+ private bool HasExistingCodes => TotpCodeList.Any(t => !t.IsDeleted);
+
/// <inheritdoc/>
protected override async Task OnInitializedAsync()
{
diff --git a/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor b/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor
index dadfae66b..69afdb284 100644
--- a/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor
+++ b/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor
@@ -692,11 +692,12 @@ else
}
/// <summary>
- /// Checks if the 2FA section can be removed (always true when visible).
+ /// Checks if the 2FA section can be removed.
+ /// Only allow removal when there's at least one TOTP code registered.
/// </summary>
private bool CanRemove2FASection()
{
- return true;
+ return Obj.TotpCodes.Any(t => !t.IsDeleted);
}
/// <summary>