Added authenication/authorization. Refactored api startup.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
@using JSMR.UI.Blazor.Services
|
||||
|
||||
@inject SessionState Session
|
||||
@inject NavigationManager Nav
|
||||
|
||||
@if (!ready)
|
||||
{
|
||||
<p>Loading...</p>
|
||||
}
|
||||
else if (!Session.IsAuthenticated)
|
||||
{
|
||||
<!-- nothing shown, we redirect -->
|
||||
}
|
||||
else
|
||||
{
|
||||
@ChildContent
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter] public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
private bool ready;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Session.RefreshAsync();
|
||||
ready = true;
|
||||
|
||||
if (!Session.IsAuthenticated)
|
||||
{
|
||||
var returnUrl = Uri.EscapeDataString(Nav.Uri);
|
||||
Nav.NavigateTo($"/login?returnUrl={returnUrl}", forceLoad: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user