Skip to content

Commit

Permalink
fix: on page reload Insights page redirecting to Dashboard (#1517)
Browse files Browse the repository at this point in the history
Co-authored-by: Deepak Paul <[email protected]>
  • Loading branch information
deepakrudrapaul and Deepak Paul authored Aug 8, 2023
1 parent c4c5609 commit 397c36e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions layouts/private-wrapper.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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");
}
}
Expand All @@ -25,7 +26,7 @@ const PrivateWrapper = ({ isPrivateRoute = false, children }: PrivateWrapperProp
if (isPrivateRoute && !user) {
checkSession();
}
}, [user]);
}, [user, isLoading]);

return <>{children}</>;
};
Expand Down

0 comments on commit 397c36e

Please sign in to comment.