diff --git a/components/Authentication/SignInForm.js b/components/Authentication/SignInForm.js index f5bd1fe..9fcb74b 100644 --- a/components/Authentication/SignInForm.js +++ b/components/Authentication/SignInForm.js @@ -33,7 +33,7 @@ const SignInForm = () => { > - + Sign In{" "} { /> - + {/* Already have an account?{" "} {
or -
+ */} { const router = useRouter(); - const [active, setActive] = useState(false); + const isAuthenticated = false; // Replace with your authentication logic - const toogleActive = () => { + const toggleActive = () => { setActive(!active); }; + const isAuthenticationPage = [ + "/authentication/sign-in", + "/authentication/sign-up", + "/authentication/forgot-password", + "/authentication/lock-screen", + "/authentication/confirm-mail", + "/authentication/logout", + ].includes(router.pathname); + return ( <> - CMC - Client + {isAuthenticated ? "CMC - Client" : "CMC - Authentication"} -
- {!( - router.pathname === "/authentication/sign-in" || - router.pathname === "/authentication/sign-up" || - router.pathname === "/authentication/forgot-password" || - router.pathname === "/authentication/lock-screen" || - router.pathname === "/authentication/confirm-mail" || - router.pathname === "/authentication/logout" - ) && ( - <> - + +
+ {!isAuthenticationPage && ( + <> + + + + )} - - - )} +
{children}
-
- {children} - - {!( - router.pathname === "/authentication/sign-in" || - router.pathname === "/authentication/sign-up" || - router.pathname === "/authentication/forgot-password" || - router.pathname === "/authentication/lock-screen" || - router.pathname === "/authentication/confirm-mail" || - router.pathname === "/authentication/logout" - ) &&
} + {!isAuthenticationPage &&
}
-
- - {/* ScrollToTop */} - - - {!( - router.pathname === "/authentication/sign-in" || - router.pathname === "/authentication/sign-up" || - router.pathname === "/authentication/forgot-password" || - router.pathname === "/authentication/lock-screen" || - router.pathname === "/authentication/confirm-mail" || - router.pathname === "/authentication/logout" - ) && - - } + + + + {!isAuthenticationPage && } +
); }; diff --git a/middlewares/AuthRoute.js b/middlewares/AuthRoute.js new file mode 100644 index 0000000..c8e0748 --- /dev/null +++ b/middlewares/AuthRoute.js @@ -0,0 +1,23 @@ +"use client" +import { useEffect } from "react"; +import { useRouter } from "next/router"; + +/** + * This is used to protect routes in a web application. + * It checks if the user is authenticated and redirects them to the sign-in page if they are not. + */ +const AuthRoute = ({ children }) => { + const router = useRouter(); + + useEffect(() => { + const isAuthenticated = false; // In a real application, this would be determined based on the user's authentication status. + + if (!isAuthenticated) { + router.push("/authentication/sign-in/"); + } + }, [router]); + + return <>{children}; +}; + +export default AuthRoute; diff --git a/pages/authentication/sign-in.js b/pages/authentication/sign-in.js index 392f744..00c63b8 100644 --- a/pages/authentication/sign-in.js +++ b/pages/authentication/sign-in.js @@ -1,9 +1,5 @@ -import SignInForm from '@/components/Authentication/SignInForm'; +import SignInForm from "@/components/Authentication/SignInForm"; export default function SignIn() { - return ( - <> - - - ); + return ; } diff --git a/pages/index.js b/pages/index.js index 54720af..2883faf 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,7 +1,7 @@ -import React from 'react'; +import React from "react"; import Grid from "@mui/material/Grid"; -import Link from 'next/link'; -import styles from '@/styles/PageTitle.module.css' +import Link from "next/link"; +import styles from "@/styles/PageTitle.module.css"; import Features from "@/components/Dashboard/eCommerce/Features"; import Ratings from "@/components/Dashboard/eCommerce/Ratings"; import AudienceOverview from "@/components/Dashboard/eCommerce/AudienceOverview"; @@ -15,8 +15,9 @@ import RecentOrders from "@/components/Dashboard/eCommerce/RecentOrders"; import TeamMembersList from "@/components/Dashboard/eCommerce/TeamMembersList"; import BestSellingProducts from "@/components/Dashboard/eCommerce/BestSellingProducts"; import LiveVisitsOnOurSite from "@/components/Dashboard/eCommerce/LiveVisitsOnOurSite"; +import AuthRoute from "middlewares/AuthRoute"; -export default function eCommerce() { +function MainPage() { return ( <> {/* Page title */} @@ -26,29 +27,20 @@ export default function eCommerce() {
  • Dashboard
  • -
  • - eCommerce -
  • +
  • eCommerce
  • - {/* Features */} - {/* AudienceOverview */} - - + {/* VisitsByDay */} - {/* Impressions */} @@ -56,32 +48,25 @@ export default function eCommerce() { {/* ActivityTimeline */} - {/* RevenuStatus */} - {/* Ratings */} - {/* LiveVisitsOnOurSite */} - {/* SalesByLocations */} - {/* NewCustomers */} - {/* Recent Orders */} - - {/* BestSellingProducts */} @@ -100,3 +84,5 @@ export default function eCommerce() { ); } + +export default MainPage \ No newline at end of file