Neighbourhood.omg.lol/Components/Pages/Login.razor
Gordon Pedersen 5fb95c8305 Added auth.
Unfortunately it does not refresh at first login. Have to figure out how to make it refresh
2024-05-31 23:16:09 +10:00

29 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));
}
}
}