Navigate user in login/logout functions
I'm trying to make it generic to send my users either to the main page or to the login page when they either login or logout but I'm having trouble doing this in a generic way.
This is my Auth Provider for example, I would like to add to the login/logout sessions a redirect.
I've tried to use
useNavigate
but get the error it should be wrapped in a <Router />
, I've tried using return <Navigate href="/" />
but this doesn't work either. Anyone able to help me out here?3 Replies
Usually Contexts are part of a Provider component. If you did that, I think it would have the behavior that you want. Also a bit suspect that you have a session signal at the root level of the page. If you'd have it inside a Provider it'd be scoped as would be expected.
@martnart Maybe I should make my Auth Guard and Auth Provider just a single component?
This is currently my Auth Guard component which I have in the root.tsx file.
Root.tsx
I think I'm mixing two things up together. Will look into this by making my AuthGuard a simple function that just guards, and make the provider the one that actually retrieves the session
This is the way