2021-01-08 16:26:19 +01:00

31 lines
768 B
Plaintext

@* @using System.Security.Claims *@
@inject AuthenticationStateProvider AuthenticationState
<AuthorizeView>
<Authorized>
<p>@context.User.Identity.Name - <button @onclick="Logout">se déconnecter</button></p>
</Authorized>
<NotAuthorized>
<p>Vous n'êtes pas connecté, <NavLink href="/login">se connecter</NavLink>.</p>
</NotAuthorized>
</AuthorizeView>
@code {
private async Task Logout()
{
await ((JwtAuthStateProvider)AuthenticationState).LogoutCurrentUser();
}
}
@* @code {
[CascadingParameter]
private Task<AuthenticationState> authenticationState { get; set; }
private ClaimsPrincipal _user;
protected override async Task OnInitializedAsync()
{
var state = await authenticationState;
_user = state.User;
}
} *@