Files
CMS-Client/middlewares/AuthRoute.js
T
2023-10-18 00:06:12 +01:00

24 lines
624 B
JavaScript

"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 = true; // 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;