Auth / beforeLoad / router.invalidate / redirect problem with router context update
i have the problem probably due to my understanding of data flow in router context?
i have simple
to trigger beforeLoad after updating react query cache
and this is my authProvider
as you can see the context does not update before beforeLoad is checked again thanks to router.invalidate
6 Replies
other-emeraldOP•17mo ago
i know i can add
but if possible I would like to know a way without using useEffect
or bast way would be just to add
cos its working that way
other-emeraldOP•17mo ago
conscious-sapphire•13mo ago
I have a similar issue with beforeLoad & AuthProvider
after successful login of user the context.auth.isAuthenticated is still giving false in context of beforeLoad and the redirection is not happening to the page after login and stays on login forever
conscious-sapphire•13mo ago
@Borcio can you try this
It fixed my issue

multiple-amethyst•13mo ago
This is not a proper fix, this is a concurrency issue, your user is not available when beforeLoad is checked because the HTTP request for the user takes time, you need to wait for the request to finish before going forward and checking if the user is authenticated.
What could fix this is a
beforeLoad
somewhere before your check if the user is authenticated that would wait for await queryClient.ensureQueryData(<user_query_options_here>)
It should look like
these could be combined into a single beforeLoad too, that would first fetch/make sure user is available then check the authentication statefascinating-indigo•12mo ago
do you guys fix this issue ? what are the solutions