This commit is contained in:
MeysamMoghaddam
2025-09-28 05:36:45 +03:30
parent d073995e02
commit 2352b7ca17
7 changed files with 116 additions and 100 deletions

View File

@@ -1,6 +1,4 @@
using System;
using System.Threading.Tasks;
using Blazored.LocalStorage;
using Blazored.LocalStorage;
using FrontOffice.Main.Utilities;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Routing;
@@ -15,22 +13,23 @@ public partial class App
private async Task HandleNavigationAsync(NavigationContext context)
{
var relativePath = Navigation.ToBaseRelativePath(context.Path);
if (IsAuthPath(relativePath))
var normalizedPath = NormalizePath(context.Path);
if (IsAuthPath(normalizedPath))
{
return;
}
var token = await LocalStorage.GetItemAsync<string>(TokenStorageKey);
if (string.IsNullOrWhiteSpace(token))
if (!string.IsNullOrWhiteSpace(token))
{
var normalized = NormalizePath(relativePath);
var redirectQuery = string.IsNullOrEmpty(normalized) || normalized == "/"
? string.Empty
: $"?redirect={Uri.EscapeDataString(normalized)}";
Navigation.NavigateTo(RouteConstants.Auth.Phone + redirectQuery, forceLoad: true);
return;
}
var redirect = string.IsNullOrEmpty(normalizedPath) || normalizedPath == "/"
? string.Empty
: $"?redirect={Uri.EscapeDataString(normalizedPath)}";
Navigation.NavigateTo(RouteConstants.Auth.Phone + redirect, forceLoad: true);
}
private static bool IsAuthPath(string? path)
@@ -40,6 +39,11 @@ public partial class App
return false;
}
if (Uri.TryCreate(path, UriKind.Absolute, out var absolute))
{
path = absolute.PathAndQuery;
}
path = path.TrimStart('/');
return path.StartsWith("auth", StringComparison.OrdinalIgnoreCase);
}
@@ -51,7 +55,12 @@ public partial class App
return string.Empty;
}
var normalized = path.StartsWith('/') ? path : "/" + path;
return normalized;
if (Uri.TryCreate(path, UriKind.Absolute, out var absolute))
{
path = absolute.PathAndQuery;
}
return path.StartsWith('/') ? path : "/" + path;
}
}