43 lines
1.2 KiB
Plaintext
43 lines
1.2 KiB
Plaintext
@using Bimix.UI.Shared.Services
|
|
@inject AuthService AuthService
|
|
@inject NavigationManager Navigation
|
|
|
|
@if (_isLoading)
|
|
{
|
|
<div class="d-flex justify-center align-center" style="height: 100vh;">
|
|
<MudProgressCircular Indeterminate="true" Size="Size.Large" />
|
|
</div>
|
|
}
|
|
else if (_isAuthenticated)
|
|
{
|
|
@ChildContent
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public RenderFragment? ChildContent { get; set; }
|
|
|
|
private bool _isLoading = true;
|
|
private bool _isAuthenticated = false;
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
Console.WriteLine("AuthGuard: Checking authentication...");
|
|
|
|
// ZAWSZE sprawdź localStorage przy inicjalizacji
|
|
_isAuthenticated = await AuthService.CheckAuthenticationAsync();
|
|
_isLoading = false;
|
|
|
|
Console.WriteLine($"AuthGuard: isAuthenticated={_isAuthenticated}");
|
|
|
|
if (!_isAuthenticated)
|
|
{
|
|
Console.WriteLine("AuthGuard: Redirecting to /login");
|
|
Navigation.NavigateTo("/login", replace: true);
|
|
}
|
|
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
} |