-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Open
Open
Copy link
Labels
Pillar: Dev Experiencearea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing one
Milestone
Description
In a Blazor component if you want to get the current user you typically have to do something like this:
protected override async Task OnInitializedAsync()
{
var authenticationState = await AuthenticationStateTask;
CurrentUser = authenticationState.User;
}
[CascadingParameter]
public Task<AuthenticationState> AuthenticationStateTask { get; set; } = default!;
public ClaimsPrincipal CurrentUser { get; set; } = default!
There are several things going on here: a special cascading parameter, overriding a component lifecycle event, and async logic to get the auth state. It's quite a bit more complicated than the convenient User
property we have in MVC & Razor Pages. And you need this code wherever you want access to the current user. Is there something we could do to cut down on the amount of boiler plate code to get the current user?
Hona and Kaayo
Metadata
Metadata
Assignees
Labels
Pillar: Dev Experiencearea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing one