Files
FrontOffice/src/FrontOffice.Main/App.razor.cs
MeysamMoghaddam 7be59c3ec3 u
2025-10-07 01:03:58 +03:30

68 lines
1.8 KiB
C#

using Blazored.LocalStorage;
using FrontOffice.Main.Utilities;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Routing;
namespace FrontOffice.Main;
public partial class App
{
private const string TokenStorageKey = "auth:token";
[Inject] private ILocalStorageService LocalStorage { get; set; } = default!;
private async Task HandleNavigationAsync(NavigationContext context)
{
// Temporarily bypass authentication to test profile page
// var normalizedPath = NormalizePath(context.Path);
// if (IsAuthPath(normalizedPath))
// {
// return;
// }
// var token = await LocalStorage.GetItemAsync<string>(TokenStorageKey);
// if (!string.IsNullOrWhiteSpace(token))
// {
// 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)
{
if (string.IsNullOrWhiteSpace(path))
{
return false;
}
if (Uri.TryCreate(path, UriKind.Absolute, out var absolute))
{
path = absolute.PathAndQuery;
}
path = path.TrimStart('/');
return path.StartsWith("auth", StringComparison.OrdinalIgnoreCase);
}
private static string NormalizePath(string? path)
{
if (string.IsNullOrWhiteSpace(path))
{
return string.Empty;
}
if (Uri.TryCreate(path, UriKind.Absolute, out var absolute))
{
path = absolute.PathAndQuery;
}
return path.StartsWith('/') ? path : "/" + path;
}
}