11 Replies
wise-whiteOP•2y ago
and my
__root.tsx
so the context in my __root is reset so the user seems non-authentificated on reload (like if I refresh the page)
but when i click on a component, the context is updated and user appear as authentifcated
this is my AuthProvider
anyone know how I can handle that ?wise-whiteOP•2y ago

wise-whiteOP•2y ago
the context in tanstack is good
but not the context in
__root.tsx
I did that in my __root.tsx
but there is a small gap that show 'login' then show 'dashboard'flat-fuchsia•2y ago
Your
useSession() likely isn't doing any data fetching. Maybe let your AuthContext be a bit more reactive and out the unneeded types.
It may also just be easier to call the useSession hook in the rootComponent since its just a single place.wise-whiteOP•2y ago
my useSession is calling the API to see if the session still OK
flat-fuchsia•2y ago
Are you injecting the queryClient into the router context?
Then,
wise-whiteOP•2y ago
mhh okay, i'll try that
what
router is related to ? edit: i'm 100% dumb
Should I remove the AuthProvider ?? (fetching the user data using useSession)wise-whiteOP•2y ago
because doing that in the root include that the user is logged,
but root contains also things that are showed if the user is unlogged, creating that

flat-fuchsia•2y ago
Its upto you. If you are storing additional data alongside the user then you keep it, else discard it.
Authenticated routes and views, heavily relies on your exact setup.
wise-whiteOP•2y ago
__root is my main page, but I still need the context
I just want the context and avoid the 'blinking component' that update itself before and after fetching
because using the ensureQueryData, it lock my route if the user is not logged in, and block the access to the website
on the root component
flat-fuchsia•2y ago
The error can very simply be handled in a try-catch block and performing a no-op on the case of an error being present. You could even check for the kind of error being thrown and handle it based on that.
If you are concerned about nothing being shown to the user whilst the ensureQueryData is being resolved, then you could set a
defaultPendingComponent on the router instance which'll be shown while the app suspends completing the fetch.
Just something to consider, is that the root route is not necessarily a layout route.