@page "/login" @using JSMR.UI.Blazor.Services @inject SessionState Session @inject NavigationManager Nav

Login

@if (Session.IsAuthenticated) {

You're already logged in as @Session.Me?.name.

} else {


@if (!string.IsNullOrWhiteSpace(error)) {

@error

}
} @code { private string username = ""; private string password = ""; private bool busy; private string? error; private async Task LoginAsync() { busy = true; error = null; try { var ok = await Session.LoginAsync(username, password); if (!ok) { error = "Invalid username or password."; return; } Nav.NavigateTo("/"); } catch (Exception ex) { error = ex.Message; } finally { busy = false; } } private async Task Logout() { busy = true; error = null; try { await Session.LogoutAsync(); } catch (Exception ex) { error = ex.Message; } finally { busy = false; } } }