diff --git a/src/components/RestrictedRoute/RestrictedRoute.tsx b/src/components/RestrictedRoute/RestrictedRoute.tsx index 3be9157b076fd142ff3f9e7a7c4b7c02b9b4bc0e..045f868d641c1bd721492147746dcaa4c69f9b05 100644 --- a/src/components/RestrictedRoute/RestrictedRoute.tsx +++ b/src/components/RestrictedRoute/RestrictedRoute.tsx @@ -4,11 +4,10 @@ import { AuthRoutes } from 'api/routes'; import { isAuthenticated } from 'api/isAuthenticated'; import { CircularProgress } from '@material-ui/core'; -/** - * - * */ type Props = { + /** Children where the authenticated user will be redirected. */ Component: React.FC<RouteProps>; + /** Path of the children. */ path: string; }; @@ -25,23 +24,11 @@ export const RestrictedRoute = ({ Component, path }: Props): JSX.Element => { const [isLoading, setLoading] = useState<boolean>(false); useEffect(() => { - let isMounted = true; - - isAuthenticated().then((state) => { - if (isMounted) { - setIsAuth(state); - setLoading(true); - } - }); - - return () => { - isMounted = false; - }; - }, [isLoading]); + isAuthenticated().then((res) => setIsAuth(res)); + console.log(isAuth); + }, [isAuth]); - return !isLoading ? ( - <CircularProgress /> - ) : ( + return ( <Route path={path} render={(props: RouteProps) =>