Call Protected APIs from a Blazor Web App

Actually if you change to call the api in OnInitializedAsync it won’t work either due to pre-rendering.

e.g.

protected override async Task OnInitializedAsync()
{
    if (authenticationState is not null)
    {
        var state = await authenticationState;

        Username = state?.User?.Identity?.Name ?? string.Empty;

        await CallInternalApi();
    }

    await base.OnInitializedAsync();
}