41 lines
No EOL
1,001 B
Text
41 lines
No EOL
1,001 B
Text
@using Blazored.LocalStorage
|
|
@inject ILocalStorageService localStorage
|
|
@inject APIService api
|
|
@inject NavigationManager Navigation
|
|
|
|
@if (IsAuthenticated) {
|
|
@ChildContent
|
|
} else {
|
|
@if (LoadingContent != null) {
|
|
@LoadingContent
|
|
} else {
|
|
<FluentProgressRing></FluentProgressRing>
|
|
}
|
|
}
|
|
|
|
@code {
|
|
public bool IsAuthenticated { get; set; } = false;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
string? jwt = await localStorage.GetItemAsync<string>("jwt");
|
|
if (jwt == null) {
|
|
Navigation.NavigateTo("/login", false);
|
|
return;
|
|
}
|
|
|
|
api.SetJwt(jwt);
|
|
bool authorized = await api.TestAuthorization();
|
|
if (authorized) {
|
|
IsAuthenticated = true;
|
|
} else {
|
|
Navigation.NavigateTo("/login", false);
|
|
}
|
|
}
|
|
|
|
[Parameter]
|
|
public required RenderFragment ChildContent { get; set; }
|
|
|
|
[Parameter]
|
|
public RenderFragment? LoadingContent { get; set; }
|
|
} |