insight/src/Web/Insight.Web/Pages/Account/Profile.razor.cs

40 lines
1.3 KiB
C#
Raw Normal View History

2023-09-21 18:58:32 +02:00
using Insight.Infrastructure.Entities;
using Insight.Infrastructure.Services;
using Insight.Web.Constants;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using MudBlazor;
namespace Insight.Web.Pages.Account;
[Route(Navigation.Account.Profile)]
public partial class Profile
{
[Parameter] public InsightUser? Account { get; set; }
[Inject] private IdentityService IdentityService { get; init; } = default!;
[Inject] private AuthenticationStateProvider AuthenticationStateProvider { get; init; } = default!;
private readonly string _title = "ProfileInsight";
private readonly List<BreadcrumbItem> _breadcrumbs = new()
{
new BreadcrumbItem("Home", href: Navigation.Home),
new BreadcrumbItem("Account", href: Navigation.Account.Profile),
new BreadcrumbItem("Profile", href: "#", true)
};
protected override async Task OnInitializedAsync()
{
await OnRefreshAsync();
}
private async Task OnRefreshAsync()
{
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (state?.User?.Identity?.Name is null) return;
Account = await IdentityService.GetByEmailAsync(state.User.Identity.Name).ConfigureAwait(false);
await InvokeAsync(StateHasChanged);
}
}