From d877de2a4cb2baa47c2b7c766d12dbc948a9d220 Mon Sep 17 00:00:00 2001 From: Terry Sutton Date: Sun, 19 Nov 2023 23:55:33 -0330 Subject: [PATCH] Move setProject out of withAuth so self-hosted still gets project ref #19046 (#19049) * Move setProject out of withAuth * Update apps/studio/hooks/misc/useStore.tsx Co-authored-by: Alaister Young --------- Co-authored-by: Alaister Young --- apps/studio/hooks/misc/useStore.tsx | 8 ++++++++ apps/studio/hooks/misc/withAuth.tsx | 9 +-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/studio/hooks/misc/useStore.tsx b/apps/studio/hooks/misc/useStore.tsx index 191e6ccad57..be8ae8c5048 100644 --- a/apps/studio/hooks/misc/useStore.tsx +++ b/apps/studio/hooks/misc/useStore.tsx @@ -4,6 +4,7 @@ import toast from 'react-hot-toast' import SparkBar from 'components/ui/SparkBar' import { IRootStore } from 'stores' +import { useSelectedProject } from './useSelectedProject' const StoreContext = createContext(undefined!) @@ -22,6 +23,13 @@ interface StoreProvider { export const StoreProvider = ({ children, rootStore }: PropsWithChildren) => { const { ui } = rootStore + const selectedProject = useSelectedProject() + useEffect(() => { + if (selectedProject) { + rootStore.setProject(selectedProject) + } + }, [selectedProject]) + useEffect(() => { autorun(() => { if (ui.notification) { diff --git a/apps/studio/hooks/misc/withAuth.tsx b/apps/studio/hooks/misc/withAuth.tsx index 4b345844e01..868d96b460d 100644 --- a/apps/studio/hooks/misc/withAuth.tsx +++ b/apps/studio/hooks/misc/withAuth.tsx @@ -3,7 +3,7 @@ import { ComponentType, useEffect } from 'react' import { usePermissionsQuery } from 'data/permissions/permissions-query' import { useAuthenticatorAssuranceLevelQuery } from 'data/profile/mfa-authenticator-assurance-level-query' -import { useSelectedProject, useStore } from 'hooks' +import { useStore } from 'hooks' import { useAuth } from 'lib/auth' import { IS_PLATFORM } from 'lib/constants' import { NextPageWithLayout, isNextPageWithLayout } from 'types' @@ -74,13 +74,6 @@ export function withAuth( } }, [session, isLoading, router, aalData, isFinishedLoading, isLoggedIn]) - const selectedProject = useSelectedProject() - useEffect(() => { - if (selectedProject) { - rootStore.setProject(selectedProject) - } - }, [selectedProject]) - const InnerComponent = WrappedComponent as any return