Files
blazor-crm/ConfigFrontEnd/Common/BaseAppPage.cs
T
2026-07-21 13:59:38 +07:00

36 lines
1.0 KiB
C#

using Indotalent.ConfigFrontEnd.Extensions;
using Indotalent.ConfigFrontEnd.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
namespace Indotalent.ConfigFrontEnd.Common;
public abstract class BaseAppPage : ComponentBase
{
[Inject]
protected AuthenticationStateProvider AuthStateProvider { get; set; } = default!;
[Inject]
protected CurrentUserState State { get; set; } = default!;
protected override async Task OnParametersSetAsync()
{
await SyncUserContext();
await base.OnParametersSetAsync();
}
private async Task SyncUserContext()
{
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
var user = authState.User;
if (user.Identity?.IsAuthenticated == true)
{
State.UserId = user.GetUserId();
State.UserName = user.GetUserName();
State.Email = user.GetEmail();
State.FullName = user.GetFullName();
}
}
}