Files
CMS-Client/middlewares/AuthRoute.js
T
2023-10-20 17:18:36 -07:00

25 lines
625 B
JavaScript

"use client";
import { useEffect, useLayoutEffect } from "react";
import { useRouter } from "next/router";
/**
* This function 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("/");
}
}, []);
return <>{children}</>;
};
export default AuthRoute;