Redirect when isAuthenticated value in context is changing
I keep my auth user in redux. I'm doing something like this;
When i'm reseting the state (logout) in redux isAuthenticated change, but the router doesn't redirect me. I have to navigate manually to the /login route.
2 Replies
foreign-sapphire•2y ago
Have you considered using
router.invalidate() after Redux has emptied the auth state?
It'd trigger a re-render upon which it'd catch the fact that the user isn't authed anymore.
All that being said, if you could also just abstract away that navigate logic into a useLogout hook as well. Just a matter of what behavior you want for your app.xenophobic-harlequinOP•2y ago
I tried using
router.invalidate() but i need to press the logout button twice to send me to the /login page. Maybe i will have to force a navigate when i sign out from the app.
Also i have an axios interceptor to sign out the user when i receive 401 response. So i have to import the router and call also manually navigate to login page.