From fbc25adb9a36234bc94450bc771cd338c0c5d8f1 Mon Sep 17 00:00:00 2001 From: bmodee <bjomo323@student.liu.se> Date: Tue, 25 May 2021 11:00:15 +0200 Subject: [PATCH] Add comments --- client/src/utils/SecureRoute.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/src/utils/SecureRoute.tsx b/client/src/utils/SecureRoute.tsx index 8e9a79bb..e880c202 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="/" />)} /> ) -- GitLab