diff --git a/frontend/src/context/WorkspaceContext/WorkspaceContext.tsx b/frontend/src/context/WorkspaceContext/WorkspaceContext.tsx index 55040a68e..29ecacaa5 100644 --- a/frontend/src/context/WorkspaceContext/WorkspaceContext.tsx +++ b/frontend/src/context/WorkspaceContext/WorkspaceContext.tsx @@ -1,4 +1,4 @@ -import { createContext, ReactNode, useContext, useMemo } from "react"; +import { createContext, ReactNode, useContext, useEffect, useMemo } from "react"; import { useRouter } from "next/router"; import { createNotification } from "@app/components/notifications"; @@ -32,22 +32,27 @@ export const WorkspaceProvider = ({ children }: Props): JSX.Element => { }; }, [ws, workspaceId, isLoading]); - // handle redirects to project-specific routes - if ( + const shouldTriggerNoProjectAccess = !value.isLoading && !value.currentWorkspace && router.pathname.startsWith("/project") && - workspaceId - ) { - createNotification({ - text: "You are not a member of this project.", - type: "info" - }); + workspaceId; - setTimeout(() => { - router.push("/"); - }, 5000); + // handle redirects for project-specific routes + useEffect(() => { + if (shouldTriggerNoProjectAccess) { + createNotification({ + text: "You are not a member of this project.", + type: "info" + }); + setTimeout(() => { + router.push("/"); + }, 5000); + } + }, [shouldTriggerNoProjectAccess, router]); + + if (shouldTriggerNoProjectAccess) { return (