Context is not up to date after navigate
Hey guys, I'm trying to handle redirection after login in.
For now, I got my Login Component that is working fine, it updates the AuthContext so I can use my user globally. I would like to be able to redirect my user to
/dashboard after the successful login.
My /dashboard route is a protected route, I can access it only if context.useris not null.
But when I'm logging in and trying to redirect, the context is not yet up to date IN THE DASHBOARD ROUTE, so I got redirect back to the login page.
Do anyone have an idea on how to solve this ?3 Replies
xenial-blackOP•2y ago
Login.tsx
Dashboard.tsx
May be there is something I don't know about context update and update in Tanstack, I'm pretty new to all of this !
Thanks!exotic-emerald•2y ago
where does your route context is updated ?
xenial-blackOP•2y ago
it is update through the
updateUser function in the onSuccess method from useMutation
The context is given to the route through the routerProvider
With this I can access the context directly in the route declaration. This is why I can access the context property on the beforeLoad method
I tried another way to redirect after login by using router.history.push('/dashboard')
But I'm still on the same point, I got redirected to login because the context is not up to date :/