I'm trying to make a redirect if the user has a token saved in cookies or not, here's my code:
const Secret = () => {
const router = useRouter();
const [token] = useState({
token: cookies.get("token") || null,
});
if (token.token == null || token.token.hasOwnProperty("error")) {
router.push("/login");
} else {
router.push("/");
}
return (
<>
<h1>Secret</h1>
</>
);
};
But I get this error: No router instance found. you should only use "next/router" inside the client side of your app. Anyone knows how to fix it? Thanks!