Fix sync redirect (#74)

This commit is contained in:
Leendert de Borst
2024-07-08 21:43:19 +02:00
parent 158a526aee
commit aa771ae1b2
2 changed files with 16 additions and 6 deletions

View File

@@ -21,6 +21,7 @@ using Microsoft.JSInterop;
/// </summary>
public class MainBase : OwningComponentBase
{
private const string ReturnUrlKey = "returnUrl";
private bool _parametersInitialSet;
/// <summary>
@@ -96,7 +97,7 @@ public class MainBase : OwningComponentBase
if (!DbService.GetState().CurrentState.IsInitialized())
{
var currentUrl = NavigationManager.Uri;
await LocalStorage.SetItemAsync("returnUrl", currentUrl);
await LocalStorage.SetItemAsync(ReturnUrlKey, currentUrl);
NavigationManager.NavigateTo("/sync");
while (true)
@@ -124,7 +125,7 @@ public class MainBase : OwningComponentBase
if (!DbService.GetState().CurrentState.IsInitialized())
{
var currentUrl = NavigationManager.Uri;
await LocalStorage.SetItemAsync("returnUrl", currentUrl);
await LocalStorage.SetItemAsync(ReturnUrlKey, currentUrl);
NavigationManager.NavigateTo("/sync");
while (true)
@@ -178,13 +179,13 @@ public class MainBase : OwningComponentBase
if (!AuthService.IsEncryptionKeySet())
{
// If returnUrl is not set and current URL is not unlock page, set it to the current URL.
var localStorageReturnUrl = await LocalStorage.GetItemAsync<string>("returnUrl");
var localStorageReturnUrl = await LocalStorage.GetItemAsync<string>(ReturnUrlKey);
if (string.IsNullOrEmpty(localStorageReturnUrl))
{
var currentUrl = NavigationManager.Uri;
if (!currentUrl.Contains("unlock"))
{
await LocalStorage.SetItemAsync("returnUrl", currentUrl);
await LocalStorage.SetItemAsync(ReturnUrlKey, currentUrl);
}
}

View File

@@ -4,6 +4,7 @@
@using AliasVault.WebApp.Main.Pages.Sync.StatusMessages
@inject ILocalStorageService LocalStorage
@inject DbService DbService
@inject AuthService AuthService
@inject NavigationManager NavigationManager
<LayoutPageTitle>Sync</LayoutPageTitle>
@@ -33,6 +34,7 @@
@code {
private const string ReturnUrlKey = "returnUrl";
private DbServiceState.DatabaseState CurrentDbState { get; set; } = new();
private const int MinimumLoadingTimeMs = 800;
@@ -43,6 +45,13 @@
DbService.GetState().StateChanged += OnDatabaseStateChanged;
CurrentDbState = DbService.GetState().CurrentState;
// Check that encryption key is set. If not, redirect to unlock screen.
if (!AuthService.IsEncryptionKeySet())
{
await LocalStorage.SetItemAsync(ReturnUrlKey, NavigationManager.Uri);
NavigationManager.NavigateTo("/unlock");
}
await CheckAndInitializeDatabase();
}
@@ -98,10 +107,10 @@
private async Task RedirectBackToReturnUrl()
{
var localStorageReturnUrl = await LocalStorage.GetItemAsync<string>("returnUrl");
var localStorageReturnUrl = await LocalStorage.GetItemAsync<string>(ReturnUrlKey);
if (!string.IsNullOrEmpty(localStorageReturnUrl) && localStorageReturnUrl != "/sync")
{
await LocalStorage.RemoveItemAsync("returnUrl");
await LocalStorage.RemoveItemAsync(ReturnUrlKey);
NavigationManager.NavigateTo(localStorageReturnUrl);
}
else