KoogleApp/src/Koogle.Web/Components/AuthTest.razor

51 lines
1.2 KiB
Plaintext

@using Koogle.Application.Interfaces
@using Koogle.Application.Services
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@inject IAuthorizationService AuthorizationService
@inject AuthenticationStateProvider AuthStateProvider
@inject IUserService UserService
@inject NavigationManager NavigationManager
@inject ICurrentClubContext CurrentClubContext
<h3>AuthTest-Component</h3>
@if (_canEdit)
{
<button class="btn btn-success">Eintrag anlegen</button>
}
else
{
<p>Keine Berechtigung zum Editieren</p>
}
<AuthorizeView Roles="SuperAdmin">
<Authorized>
<button class="btn btn-primary">Club anlegen</button>
</Authorized>
</AuthorizeView>
<AuthorizeView>
aktueller Club: @CurrentClubContext.ClubName
<LogoutButton/>
</AuthorizeView>
@code {
private bool _canEdit;
protected override async Task OnParametersSetAsync()
{
var state = await AuthStateProvider.GetAuthenticationStateAsync();
var user = state.User;
var result = await AuthorizationService.AuthorizeAsync(user, CurrentClubContext.ClubId, "ClubEditor");
_canEdit = result.Succeeded;
}
}