trying to fix protected route data fetch problem and only one more problem somewhere in the

This commit is contained in:
Arjun Patel
2022-02-09 16:07:04 -08:00
parent 067408f104
commit 2f79f769cc
7 changed files with 44 additions and 25 deletions
+22
View File
@@ -0,0 +1,22 @@
import { useRouter } from "next/router";
import toast from "react-hot-toast";
import { useAuth } from "./authContext";
import { useEffect } from "react";
export default function ProtectedRoute({ children }) {
const { currUser } = useAuth();
// figure out what content to render from here
const router = useRouter();
// useEffect(() => {}, []);
if (!currUser) {
console.log("not authenticated...routing from dashboard to teams home");
toast.error("Not Authenticated");
router.push("/teams/login");
return <></>;
}
return <>{currUser && children}</>;
}