From 86ccccb95d044432e304495ba15ef28e73cc3cd2 Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Wed, 23 Oct 2024 22:01:22 +0200 Subject: [PATCH 1/2] Improve error message for unlock page if API cannot be reached (#320) --- src/AliasVault.Client/Auth/Pages/Unlock.razor | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/AliasVault.Client/Auth/Pages/Unlock.razor b/src/AliasVault.Client/Auth/Pages/Unlock.razor index 2537bd47c..a74a49cee 100644 --- a/src/AliasVault.Client/Auth/Pages/Unlock.razor +++ b/src/AliasVault.Client/Auth/Pages/Unlock.razor @@ -9,6 +9,9 @@ @using AliasVault.Shared.Models.WebApi.Auth @using AliasVault.Cryptography.Client + + + @if (IsLoading) { @@ -38,7 +41,7 @@ else Unlock with WebAuthn @@ -49,9 +52,6 @@ else Enter your master password to unlock your database.

- - -
@@ -94,10 +94,7 @@ else { // Trigger status API call to check if the user is still authenticated. // If user is not authenticated a redirect to the login page will be triggered automatically. - await Task.WhenAll( - Http.GetAsync("api/v1/Auth/status"), - StatusCheck() - ); + await StatusCheck(); // Always check if WebAuthn is enabled ShowWebAuthnButton = await AuthService.IsWebAuthnEnabledAsync(); @@ -124,7 +121,6 @@ else try { await StatusCheck(); - await Http.GetAsync("api/v1/Auth/status"); // Send request to server with email to get user salt. var result = await Http.PostAsJsonAsync("api/v1/Auth/login", new LoginInitiateRequest(Username!)); @@ -137,6 +133,7 @@ else { _serverValidationErrors.AddError(error); } + return; } @@ -230,6 +227,20 @@ else GlobalNotificationService.ClearMessages(); GlobalNotificationService.AddErrorMessage("Your session has timed out. Please log in again."); NavigationManager.NavigateTo("/user/login"); + return; + } + + // Make a request to the server to check if the user is still authenticated. + // If user has no valid authentication an automatic redirect to login page will take place. + try + { + await Http.GetAsync("api/v1/Auth/status"); + } + catch (Exception ex) + { + _serverValidationErrors.AddError("Connection with the AliasVault servers failed. Please try again (later)."); + Logger.LogError(ex, "An error occurred while checking the user status."); + StateHasChanged(); } } From 9ec1d83de9abae4345ffc93a15cddd780b0834cd Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Thu, 24 Oct 2024 20:02:35 +0200 Subject: [PATCH 2/2] Update Unlock.razor (#320) --- src/AliasVault.Client/Auth/Pages/Unlock.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AliasVault.Client/Auth/Pages/Unlock.razor b/src/AliasVault.Client/Auth/Pages/Unlock.razor index a74a49cee..ce33287fb 100644 --- a/src/AliasVault.Client/Auth/Pages/Unlock.razor +++ b/src/AliasVault.Client/Auth/Pages/Unlock.razor @@ -180,7 +180,7 @@ else catch { // If in release mode show a generic error. - ServerValidationErrors.AddError("An error occurred while processing the login request. Try again (later)."); + _serverValidationErrors.AddError("An error occurred while processing the login request. Try again (later)."); } #endif finally