79723594

Date: 2025-08-02 19:01:53
Score: 1.5
Natty:
Report link

This issue may be caused by the HTTP request to api/users/me being made too early, before the authentication cookies for API requests are fully set.

To resolve this issue, use a wait and UI update process, as in the sample code below, to have the system wait a while for the logged-in user to be marked as authenticated.

If the error persists, please share the ApiService and UserService codes so I can investigate further and provide further assistance.

@code {
    private bool _loaded = false;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender && !_loaded)
        {
            var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
            var user = authState.User;

            if (user.Identity is not null && user.Identity.IsAuthenticated)
            {
                try
                {
                    await UserService.LoadCurrentUserAsync();
                    _loaded = true;
                    StateHasChanged(); // Update UI for get the changes
                }
                catch (Exception ex)
                {
                    await Console.Error.WriteLineAsync("Error with LoadCurrentUserAsync: " + ex.Message);
                }
            }
        }
    }
}
Reasons:
  • RegEx Blacklisted phrase (2.5): please share
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Yusuf