autoredirect to login page
This commit is contained in:
parent
ea7066ae93
commit
4d2cf4bbc5
1 changed files with 8 additions and 25 deletions
|
@ -3,20 +3,8 @@
|
||||||
@inject APIService api
|
@inject APIService api
|
||||||
@inject NavigationManager Navigation
|
@inject NavigationManager Navigation
|
||||||
|
|
||||||
@if (IsReady) {
|
|
||||||
@if (IsAuthenticated) {
|
@if (IsAuthenticated) {
|
||||||
@ChildContent
|
@ChildContent
|
||||||
} else {
|
|
||||||
<FluentLayout>
|
|
||||||
<FluentHeader>
|
|
||||||
Blazing Console
|
|
||||||
</FluentHeader>
|
|
||||||
<FluentBodyContent>
|
|
||||||
<h1>Log in first</h1>
|
|
||||||
<FluentButton Appearance="@Appearance.Accent" OnClick="LoginButtonClicked">Log in</FluentButton>
|
|
||||||
</FluentBodyContent>
|
|
||||||
</FluentLayout>
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
@if (LoadingContent != null) {
|
@if (LoadingContent != null) {
|
||||||
@LoadingContent
|
@LoadingContent
|
||||||
|
@ -25,30 +13,25 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
public bool IsReady { get; set; } = false;
|
|
||||||
public bool IsAuthenticated { get; set; } = false;
|
public bool IsAuthenticated { get; set; } = false;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
string? jwt = await localStorage.GetItemAsync<string>("jwt");
|
string? jwt = await localStorage.GetItemAsync<string>("jwt");
|
||||||
if (jwt == null) {
|
if (jwt == null) {
|
||||||
IsAuthenticated = false;
|
Navigation.NavigateTo("/login", false);
|
||||||
IsReady = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
api.SetJwt(jwt);
|
api.SetJwt(jwt);
|
||||||
bool authorized = await api.TestAuthorization();
|
bool authorized = await api.TestAuthorization();
|
||||||
IsAuthenticated = authorized;
|
if (authorized) {
|
||||||
IsReady = true;
|
IsAuthenticated = true;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
public void LoginButtonClicked() {
|
|
||||||
Navigation.NavigateTo("/login", false);
|
Navigation.NavigateTo("/login", false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public required RenderFragment ChildContent { get; set; }
|
public required RenderFragment ChildContent { get; set; }
|
||||||
|
|
Loading…
Reference in a new issue