import { checkAuth } from "@/utils/auth"; import { useRouter } from "next/navigation"; import { useEffect } from "react"; import { get } from "@/utils/storeInfo"; export default function WithAuth(WrappedComponent) { const router = useRouter(); useEffect(() => { checkLogin(); // console.log("isLogin",isLogin) }, []); const checkLogin = async () => { const hasToken = get("token"); console.log("hasToken", hasToken); if (hasToken) { const hasToken = get("token"); console.log("hasToken", hasToken); if (hasToken) { const currentIsLogin = await checkAuth(); if (!currentIsLogin) { router.push("/login") } } }else{ router.push("/login") } }; return WrappedComponent; }