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 <alaister@users.noreply.github.com>

---------

Co-authored-by: Alaister Young <alaister@users.noreply.github.com>
This commit is contained in:
Terry SuttonandAlaister Young authored and GitHub committed 2023-11-20 14:25:33 +11:00
1 parent 2a4e4442b0
commit d877de2a4c
2 files changed
+9 -8

No files matched your search

+8
View File
@@ -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<IRootStore>(undefined!)
@@ -22,6 +23,13 @@ interface StoreProvider {
export const StoreProvider = ({ children, rootStore }: PropsWithChildren<StoreProvider>) => {
const { ui } = rootStore
const selectedProject = useSelectedProject()
useEffect(() => {
if (selectedProject) {
rootStore.setProject(selectedProject)
}
}, [selectedProject])
useEffect(() => {
autorun(() => {
if (ui.notification) {
+1 -8
View File
@@ -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<T>(
}
}, [session, isLoading, router, aalData, isFinishedLoading, isLoggedIn])
const selectedProject = useSelectedProject()
useEffect(() => {
if (selectedProject) {
rootStore.setProject(selectedProject)
}
}, [selectedProject])
const InnerComponent = WrappedComponent as any
return <InnerComponent {...props} />