25 lines
926 B
Plaintext
25 lines
926 B
Plaintext
@inject AuthenticationStateProvider AuthProvider
|
|
@inject IUserService UserService
|
|
@inject IUserContextAccessor UserContext
|
|
@using Microsoft.AspNetCore.Components.Authorization
|
|
@using SharepointToolbox.Web.Services.Auth
|
|
@using SharepointToolbox.Web.Services.Session
|
|
|
|
@* Invisible component. Run once per circuit to seed IUserContextAccessor. *@
|
|
|
|
@code {
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
var state = await AuthProvider.GetAuthenticationStateAsync();
|
|
var principal = state.User;
|
|
if (principal.Identity?.IsAuthenticated != true) return;
|
|
|
|
var email = principal.FindFirst("preferred_username")?.Value
|
|
?? principal.FindFirst(System.Security.Claims.ClaimTypes.Email)?.Value;
|
|
if (string.IsNullOrEmpty(email)) return;
|
|
|
|
var user = await UserService.GetByEmailAsync(email);
|
|
if (user is not null) UserContext.Initialize(user);
|
|
}
|
|
}
|