Closed fdonnet closed 10 months ago
This guy bcheung4589 helped me a lot with the explanation here https://github.com/dotnet/aspnetcore/issues/51468 to manage auto mode... that's why I had my issue and his facade proposition works for me... now that my page is called from server first and from wasm after, I only need to understand why my initial data load is cleaned after the first render
I have a direct answer for you, as Ive experienced this personally.
Problem: on the second run, UserServiceMiddleware isnt executed and so UserService stays empty => with all its further consequences.
Solution: what to do? Refactor UserService with RequireUserAsync(ClaimsPrincipal user).
Implementation: in the razor component (yes, Im also not 100% satisfied with this solution, but it works for now):
protected override async Task OnInitializedAsync()
{
// Require User or move away.
await UserService.RequireUserAsync(AuthenticationStateProvider, Navigation);
// Run as usual.
await base.OnInitializedAsync();
}
Is there an existing issue for this?
Describe the bug
When I call an api from a blazor page I think my middleware crash and I don't understand why
If the api call is called inside OnInitializedAsync it doesn't work, when it's trigger by the Hello button outside of OnInitializedAsync it works.
I wait the authenticatioState correctly I think.
It crash server side in my user middleware, when I set my user
(like explained here https://learn.microsoft.com/en-us/aspnet/core/blazor/security/server/additional-scenarios?view=aspnetcore-8.0) to be able to inject my user in other services server side.
Very strange.
Expected Behavior
Same behavior as calling the API with a button click... I'dont understand why my middleware creates this issue for OnInitializedAsync. It crash on await next(context);
Steps To Reproduce
No response
Exceptions (if any)
it returns
.NET Version
8.0
Anything else?
No response