Files
CMS-Client/middlewares/AuthRoute.js
T
2023-10-22 07:08:04 -07:00

37 lines
789 B
JavaScript

"use client"
import { useEffect } from "react";
import { useRouter } from "next/router";
const AuthRoute = ({ children }) => {
const router = useRouter();
const token = req.cookies["cmc-token"]; // Access the token from cookies
useEffect(() => {
const isAuthenticated = token ? true : false;
// if (router.pathname === "/auth/login" && isAuthenticated) {
// router.push("/");
// }
// if (!authenticationPages.includes(router.pathname) && !isAuthenticated) {
// router.push("/auth/login");
// }
}, []);
return <>{children}</>;
};
export default AuthRoute;
const authenticationPages = [
// "/",
"/auth",
"/auth/login",
"/auth/sign-up",
"/auth/forgot-password",
"/auth/lock-screen",
"/auth/confirm-mail",
"/auth/logout",
];