From 397c36eab096f5a43ef09a8c528f13ada5cc4940 Mon Sep 17 00:00:00 2001 From: Deepak Rudra Paul Date: Tue, 8 Aug 2023 19:02:04 +0530 Subject: [PATCH] fix: on page reload Insights page redirecting to Dashboard (#1517) Co-authored-by: Deepak Paul --- layouts/private-wrapper.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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}; };