Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Refactor isEncryptionKeySet logic to prevent delayed navigation loops (#60)
Leendert de Borst75933efbdd91
diff --git a/src/AliasVault.WebApp/Auth/Services/AuthService.cs b/src/AliasVault.WebApp/Auth/Services/AuthService.csindex c84648534..7542b06c2 100644--- a/src/AliasVault.WebApp/Auth/Services/AuthService.cs+++ b/src/AliasVault.WebApp/Auth/Services/AuthService.cs@@ -110,6 +110,27 @@ public class AuthService(HttpClient httpClient, ILocalStorageService localStoragreturn Convert.ToBase64String(GetEncryptionKeyAsync());}+ /// <summary>+ /// Returns whether the encryption key is set.+ /// </summary>+ /// <returns>Return true if encryption key is set, otherwise false.</returns>+ public bool IsEncryptionKeySet()+ {+ // Check that encryption key is set. If not, redirect to unlock screen.+ var encryptionKey = GetEncryptionKeyAsBase64Async();+ if (encryptionKey == string.Empty)+ {+ return false;+ }++ if (encryptionKey == "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")+ {+ return false;+ }++ return true;+ }+/// <summary>/// Stores the encryption key asynchronously in-memory./// </summary>diff --git a/src/AliasVault.WebApp/Pages/Base/PageBase.cs b/src/AliasVault.WebApp/Pages/Base/PageBase.csindex a9e6cb32f..97397afd1 100644--- a/src/AliasVault.WebApp/Pages/Base/PageBase.cs+++ b/src/AliasVault.WebApp/Pages/Base/PageBase.cs@@ -134,8 +134,7 @@ public class PageBase : OwningComponentBase}// Check that encryption key is set. If not, redirect to unlock screen.- if (string.IsNullOrEmpty(AuthService.GetEncryptionKeyAsBase64Async()) ||- AuthService.GetEncryptionKeyAsBase64Async() == "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")+ if (!AuthService.IsEncryptionKeySet()){var currentUrl = NavigationManager.Uri;await LocalStorage.SetItemAsync("returnUrl", currentUrl);diff --git a/src/AliasVault.WebApp/Services/AliasClientDbService.cs b/src/AliasVault.WebApp/Services/AliasClientDbService.csindex 118b0c8a0..8c8dd0f54 100644--- a/src/AliasVault.WebApp/Services/AliasClientDbService.cs+++ b/src/AliasVault.WebApp/Services/AliasClientDbService.cs@@ -196,6 +196,12 @@ public class AliasClientDbServiceprivate async Task InitializeDatabaseAsync(){+ // Check that encryption key is set. If not, do nothing.+ if (!_authService.IsEncryptionKeySet())+ {+ return;+ }+// Create a new in-memory database.string connectionString = "Data Source=AliasClientDb.sqlite";using var connection = new SqliteConnection(connectionString);diff --git a/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs b/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.csindex 9cf366273..2cb49fc6c 100644--- a/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs+++ b/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs@@ -185,7 +185,7 @@ public class PlaywrightTest// Check that we get redirected to /user/login when accessing the root URL and not authenticated.await Page.GotoAsync(AppBaseUrl);- await WaitForURLAsync("**/user/login", 20000);+ await WaitForURLAsync("**/user/login");// Try to register a new account.var registerButton = Page.Locator("a[href='/user/register']");@@ -206,6 +206,7 @@ public class PlaywrightTest// Check if we get redirected when clicking on the register button.var submitButton = Page.Locator("button[type='submit']");+ Console.WriteLine(submitButton);await submitButton.ClickAsync();// Check if we get redirected to the root URL after registration which means we are logged in.