diff --git a/client/src/Components/HOC/withAdminCheck.jsx b/client/src/Components/HOC/withAdminCheck.jsx index 8edf7a02b..bd6a21d07 100644 --- a/client/src/Components/HOC/withAdminCheck.jsx +++ b/client/src/Components/HOC/withAdminCheck.jsx @@ -1,4 +1,4 @@ -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import { logger } from "../../Utils/Logger"; @@ -7,23 +7,35 @@ import { networkService } from "../../main"; const withAdminCheck = (WrappedComponent) => { const WithAdminCheck = (props) => { const navigate = useNavigate(); + const [isChecking, setIsChecking] = useState(true); + const [superAdminExists, setSuperAdminExists] = useState(false); useEffect(() => { networkService .doesSuperAdminExist() .then((response) => { - if (response.data.data === true) { + if (response?.data?.data === true) { navigate("/login"); + } else { + setSuperAdminExists(true); } }) .catch((error) => { logger.error(error); + }) + .finally(() => { + setIsChecking(false); }); }, [navigate]); + + if (isChecking) { + return null; + } + return ( ); };