Files
blazor-saas-hrm/ConfigFrontEnd/Common/BaseAppPage.cs
T
2026-07-21 14:22:06 +07:00

37 lines
1.1 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();
State.TenantId = user.GetTenantId();
}
}
}