From 113cca276553e653a5b64ec5b545f6f0f919c0ab Mon Sep 17 00:00:00 2001 From: Juan Pablo Vega Date: Tue, 26 Nov 2024 16:22:04 +0100 Subject: [PATCH] WIP --- agenta-web/src/components/Layout/Layout.tsx | 2 +- .../src/components/ProtectedRoute/ProtectedRoute.tsx | 10 ++++++---- agenta-web/src/contexts/project.context.tsx | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/agenta-web/src/components/Layout/Layout.tsx b/agenta-web/src/components/Layout/Layout.tsx index ac8c491e42..6b0d299575 100644 --- a/agenta-web/src/components/Layout/Layout.tsx +++ b/agenta-web/src/components/Layout/Layout.tsx @@ -170,7 +170,7 @@ const App: React.FC = ({children}) => { {typeof window === "undefined" ? null : ( - {isAuthRoute || !isProjectId ? ( + {isAuthRoute ? ( {children} diff --git a/agenta-web/src/components/ProtectedRoute/ProtectedRoute.tsx b/agenta-web/src/components/ProtectedRoute/ProtectedRoute.tsx index d986e26e7b..1080fe546f 100644 --- a/agenta-web/src/components/ProtectedRoute/ProtectedRoute.tsx +++ b/agenta-web/src/components/ProtectedRoute/ProtectedRoute.tsx @@ -1,22 +1,24 @@ import {useSession} from "@/hooks/useSession" import {useRouter} from "next/router" import React, {PropsWithChildren, useEffect, useState} from "react" +import {useProjectData} from "@/contexts/project.context" const ProtectedRoute: React.FC = ({children}) => { const router = useRouter() const {loading, doesSessionExist: isSignedIn} = useSession() const {pathname} = router const [shouldRender, setShouldRender] = useState(false) + const {isLoading, isProjectId} = useProjectData() useEffect(() => { - if (loading) { + if (loading || isLoading) { setShouldRender(false) } else { if (pathname.startsWith("/auth")) { if (isSignedIn) { router.push("/apps") } - setShouldRender(!isSignedIn) + setShouldRender(true) } else { if (!isSignedIn) { router.push( @@ -25,10 +27,10 @@ const ProtectedRoute: React.FC = ({children}) => { )}`, ) } - setShouldRender(isSignedIn) + setShouldRender(!!isProjectId) } } - }, [pathname, isSignedIn, loading]) + }, [pathname, isSignedIn, loading, isProjectId, isLoading]) return <>{shouldRender ? children : null} } diff --git a/agenta-web/src/contexts/project.context.tsx b/agenta-web/src/contexts/project.context.tsx index a527320d20..ddcb2b5781 100644 --- a/agenta-web/src/contexts/project.context.tsx +++ b/agenta-web/src/contexts/project.context.tsx @@ -44,7 +44,7 @@ export const getCurrentProject = () => projectContextValues const ProjectContextProvider: React.FC = ({children}) => { const [project, setProject] = useStateCallback(null) const [useOrgData, setUseOrgData] = useState(() => () => "") - const [isLoading, setIsLoading] = useState(true) + const [isLoading, setIsLoading] = useState(false) const {doesSessionExist} = useSession() useEffect(() => { @@ -103,7 +103,7 @@ const ProjectContextProvider: React.FC = ({children}) => { refetch: fetcher, }} > - {isProjectId ? children : null} + {children} ) }