I’m trying to prevent pages’ loading ‘/login’ and ‘/signup’ if user is already authenticated.
As suggested in another thread, I’ve implemented ‘AuthRedirect’ component as follow:
const AuthRedirect = ({ children }) => {
const { isAuthenticated } = useAuth()
if (isAuthenticated) {
return <Redirect to={routes.dashboard()} />
}
return children
}
My route’s file is as follow:
<Router>
<Private unauthenticated="login" wrap={DashboardLayout}>
<Route path="/dashboard" page={DashboardPage} name="dashboard" />
</Private>
<Set wrap={[AuthRedirect, AuthLayout]}>
<Route path="/signup" page={SignupPage} name="signup" />
<Route path="/login" page={LoginPage} name="login" />
</Set>
<Route notfound page={NotFoundPage} />
</Router>
So far so good.
But the problem is when I visit for the first time ‘/login’ or ‘/signup’ pages. For a while (and before the redirect) the page flickers showing me the AuthLayout.
How can I solve this?
Thanks