formatted
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user