Files
mapo-core/MP.Stats/Components/CmpTop.razor
T
2021-05-17 13:35:20 +02:00

52 lines
1.4 KiB
Plaintext

@using MP.Stats.Components
@using System.Security.Claims
@using Microsoft.AspNetCore.Components.Authorization
@inject AuthenticationStateProvider AuthenticationStateProvider
<div class="row pt-3">
<div class="col-4">
<i class="fas fa-user-alt"></i> <b>@userName</b>
</div>
<div class="col-4">
</div>
<div class="col-4 text-right">
@if (ShowSearch)
{
<SearchMod></SearchMod>
}
</div>
</div>
@code {
[CascadingParameter(Name = "ShowSearch")]
private bool ShowSearch { get; set; }
private string userName = "";
protected override async Task OnInitializedAsync()
{
await forceReload();
}
private async Task forceReload()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;
if (user.Identity.IsAuthenticated)
{
userName = $"{user.Identity.Name}";
}
else
{
userName = "N.A.";
}
}
}
@* // Vedere anche:
// https://docs.microsoft.com/en-us/aspnet/core/blazor/security/?view=aspnetcore-5.0#:~:text=Blazor%20uses%20the%20existing%20ASP.NET%20Core%20authentication%20mechanisms,all%20client-side%20code%20can%20be%20modified%20by%20users
// https://docs.microsoft.com/en-us/aspnet/core/blazor/security/?view=aspnetcore-5.0*@