@page "/login"
@using Microsoft.AspNetCore.Components.Authorization
@using System.Security.Claims
@inject NavigationManager navigationManager
@inject AuthenticationStateProvider AuthStateProvider
Login
@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));
}
}
}