formatted

This commit is contained in:
Amirhossein Mahmoodi
2024-07-09 13:58:13 +03:30
parent 863bdaca95
commit bc73725138
82 changed files with 2206 additions and 3082 deletions

View File

@@ -1,22 +1,22 @@
'use client'
"use client";
import { useAuth } from "@/lib/contexts/auth";
import { usePathname, useRouter } from "next/navigation";
import { useEffect } from "react";
function WithAuthMiddleware({ children }) {
const router = useRouter()
const pathName = usePathname()
const router = useRouter();
const pathName = usePathname();
const { isAuth, initAuthState } = useAuth();
useEffect(() => {
if (!initAuthState) return
if (!initAuthState) return;
if (!isAuth) {
router.replace(`${process.env.NEXT_PUBLIC_API_URL}/login?_back=${encodeURIComponent(pathName)}`)
router.replace(`${process.env.NEXT_PUBLIC_API_URL}/login?_back=${encodeURIComponent(pathName)}`);
}
}, [isAuth, initAuthState])
}, [isAuth, initAuthState]);
if (!initAuthState || !isAuth) return null;
return <>{children}</>
return <>{children}</>;
}
export default WithAuthMiddleware
export default WithAuthMiddleware;