diff --git a/layouts/private-wrapper.tsx b/layouts/private-wrapper.tsx index 170d51be00..0167981a4c 100644 --- a/layouts/private-wrapper.tsx +++ b/layouts/private-wrapper.tsx @@ -1,4 +1,4 @@ -import { useUser } from "@supabase/auth-helpers-react"; +import { useSessionContext, useUser } from "@supabase/auth-helpers-react"; import { useRouter } from "next/router"; import React, { useEffect } from "react"; import useSession from "lib/hooks/useSession"; @@ -11,12 +11,13 @@ interface PrivateWrapperProps { const PrivateWrapper = ({ isPrivateRoute = false, children }: PrivateWrapperProps) => { const user = useUser(); const router = useRouter(); + const { isLoading } = useSessionContext(); const { session: isValid } = useSession(true); async function checkSession() { if (router.asPath?.includes("login")) return; - if (!isValid) { + if (!isValid && !isLoading) { router.replace("/javascript/dashboard/filter/recent"); } } @@ -25,7 +26,7 @@ const PrivateWrapper = ({ isPrivateRoute = false, children }: PrivateWrapperProp if (isPrivateRoute && !user) { checkSession(); } - }, [user]); + }, [user, isLoading]); return <>{children}; };