identity blazor
i have this code for getting user id of current user but its return null i use blazor wasm and web api
csharp protected override async Task OnParametersSetAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;
if (string.IsNullOrEmpty(userId) && user.Identity.IsAuthenticated)
{
var userIdClaim = user.FindFirst(c => c.Type == "sub");
userId = userIdClaim?.Value;
}
await LoadProfileData();
}csharp protected override async Task OnParametersSetAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;
if (string.IsNullOrEmpty(userId) && user.Identity.IsAuthenticated)
{
var userIdClaim = user.FindFirst(c => c.Type == "sub");
userId = userIdClaim?.Value;
}
await LoadProfileData();
}