Added authenication/authorization. Refactored api startup.
This commit is contained in:
@@ -1,4 +1,20 @@
|
||||
@inherits LayoutComponentBase
|
||||
@using JSMR.UI.Blazor.Services
|
||||
|
||||
@inject SessionState Session
|
||||
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
<div class="topbar">
|
||||
@if (Session.IsAuthenticated)
|
||||
{
|
||||
<span>Logged in as <b>@Session.Me?.name</b> (@Session.Me?.role)</span>
|
||||
<a href="" @onclick="OnLogout" style="margin-left: 12px;">Logout</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<a href="/login">Login</a>
|
||||
}
|
||||
</div>
|
||||
|
||||
<MudLayout>
|
||||
<MudAppBar Elevation="1" Dense="@_dense">
|
||||
@@ -56,4 +72,21 @@
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Session.Changed += OnSessionChanged;
|
||||
}
|
||||
|
||||
private void OnSessionChanged() => InvokeAsync(StateHasChanged);
|
||||
|
||||
private async Task OnLogout(MouseEventArgs _)
|
||||
{
|
||||
await Session.LogoutAsync();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Session.Changed -= OnSessionChanged;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user