Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-agenta committed Nov 26, 2024
1 parent d96dc0f commit 113cca2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion agenta-web/src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const App: React.FC<LayoutProps> = ({children}) => {
<NoSSRWrapper>
{typeof window === "undefined" ? null : (
<ThemeProvider theme={{...token, isDark: isDarkTheme}}>
{isAuthRoute || !isProjectId ? (
{isAuthRoute ? (
<Layout className={classes.layout}>
<ErrorBoundary FallbackComponent={ErrorFallback}>
{children}
Expand Down
10 changes: 6 additions & 4 deletions agenta-web/src/components/ProtectedRoute/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
@@ -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<PropsWithChildren> = ({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(
Expand All @@ -25,10 +27,10 @@ const ProtectedRoute: React.FC<PropsWithChildren> = ({children}) => {
)}`,
)
}
setShouldRender(isSignedIn)
setShouldRender(!!isProjectId)
}
}
}, [pathname, isSignedIn, loading])
}, [pathname, isSignedIn, loading, isProjectId, isLoading])

return <>{shouldRender ? children : null}</>
}
Expand Down
4 changes: 2 additions & 2 deletions agenta-web/src/contexts/project.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const getCurrentProject = () => projectContextValues
const ProjectContextProvider: React.FC<PropsWithChildren> = ({children}) => {
const [project, setProject] = useStateCallback<Project | null>(null)
const [useOrgData, setUseOrgData] = useState<Function>(() => () => "")
const [isLoading, setIsLoading] = useState(true)
const [isLoading, setIsLoading] = useState(false)
const {doesSessionExist} = useSession()

useEffect(() => {
Expand Down Expand Up @@ -103,7 +103,7 @@ const ProjectContextProvider: React.FC<PropsWithChildren> = ({children}) => {
refetch: fetcher,
}}
>
{isProjectId ? children : null}
{children}
</ProjectContext.Provider>
)
}
Expand Down

0 comments on commit 113cca2

Please sign in to comment.