30 lines
763 B
Text
30 lines
763 B
Text
|
|
@page "/login"
|
||
|
|
@using Microsoft.AspNetCore.Components.Authorization
|
||
|
|
@using System.Security.Claims
|
||
|
|
@inject NavigationManager navigationManager
|
||
|
|
@inject AuthenticationStateProvider AuthStateProvider
|
||
|
|
<h3>Login</h3>
|
||
|
|
|
||
|
|
@code {
|
||
|
|
|
||
|
|
protected override async Task OnInitializedAsync() {
|
||
|
|
await checkLogin();
|
||
|
|
}
|
||
|
|
|
||
|
|
// protected override async Task OnAfterRenderAsync(bool firstRender) {
|
||
|
|
// await checkLogin();
|
||
|
|
// }
|
||
|
|
|
||
|
|
private async Task checkLogin() {
|
||
|
|
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
|
||
|
|
var user = authState.User;
|
||
|
|
|
||
|
|
if (user.Identity is not null && user.Identity.IsAuthenticated) {
|
||
|
|
navigationManager.NavigateTo("/");
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
await Shell.Current.GoToAsync(nameof(LoginWebViewPage));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|