Jelajahi Sumber

Clearer logic on GuardedRoute component

jnfrati 4 tahun lalu
induk
melakukan
c98defe9e8
1 mengubah file dengan 8 tambahan dan 8 penghapusan
  1. 8 8
      dashboard/src/shared/auth/RouteGuard.tsx

+ 8 - 8
dashboard/src/shared/auth/RouteGuard.tsx

@@ -24,14 +24,14 @@ const GuardedRoute: React.FC<RouteProps & GuardedRouteProps> = ({
     return isAuthorized(currentPolicy, scope, resource, verb);
   }, [currentPolicy, scope, resource, verb]);
 
-  return (
-    <Route
-      {...rest}
-      render={(props) =>
-        auth ? children || <Component {...props} /> : <UnauthorizedPage />
-      }
-    />
-  );
+  const render = (props: any) => {
+    if (auth) {
+      return children || <Component {...props} />;
+    }
+    return <UnauthorizedPage />;
+  };
+
+  return <Route {...rest} render={render} />;
 };
 
 export const fakeGuardedRoute = <ComponentProps extends object>(