diff --git a/client/src/utils/SecureRoute.tsx b/client/src/utils/SecureRoute.tsx index 8e9a79bbe7d3d57f0ce48ae740779c359d9eb9d4..e880c20274ed4bae5bfc8803f7b2eb0dd93afb5f 100644 --- a/client/src/utils/SecureRoute.tsx +++ b/client/src/utils/SecureRoute.tsx @@ -27,6 +27,7 @@ const SecureRoute: React.FC<SecureRouteProps> = ({ component: Component, authLev } }, []) + // If the user is authenticated and wants to log in, redirect to the correct path if (initialized) { if (authLevel === 'login') return ( @@ -35,6 +36,7 @@ const SecureRoute: React.FC<SecureRouteProps> = ({ component: Component, authLev render={(props) => (userAuthenticated ? <Redirect to="/admin" /> : <Component {...props} />)} /> ) + // the user does not have access to the admin page else if (compInitialized && viewType && authLevel !== 'admin') { return ( <Route @@ -44,7 +46,9 @@ const SecureRoute: React.FC<SecureRouteProps> = ({ component: Component, authLev } /> ) - } else + } + // the user does not have access to the admin page + else return ( <Route {...rest} render={(props) => (userAuthenticated ? <Component {...props} /> : <Redirect to="/" />)} /> )