identity blazor

i have this code for getting user id of current user but its return null
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();
    }
i use blazor wasm and web api
Was this page helpful?