Files
jsmr/JSMR.UI.Blazor/Services/SessionState.cs
Brian Bicknell 9f30ef446a
Some checks failed
ci / build-test (push) Has been cancelled
ci / publish-image (push) Has been cancelled
Added authenication/authorization. Refactored api startup.
2026-02-16 00:20:02 -05:00

28 lines
784 B
C#

namespace JSMR.UI.Blazor.Services;
public sealed class SessionState(AuthenticationClient auth)
{
public AuthenticationClient.MeResponse? Me { get; private set; }
public bool IsAuthenticated => Me is not null;
public event Action? Changed;
public async Task RefreshAsync(CancellationToken ct = default)
{
Me = await auth.GetMeAsync(ct);
Changed?.Invoke();
}
public async Task<bool> LoginAsync(string username, string password, CancellationToken ct = default)
{
var ok = await auth.LoginAsync(username, password, ct);
await RefreshAsync(ct);
return ok;
}
public async Task LogoutAsync(CancellationToken ct = default)
{
await auth.LogoutAsync(ct);
await RefreshAsync(ct);
}
}