The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Update perms to access storage
Joshen Lim313318544d55
diff --git a/studio/components/layouts/StorageLayout/StorageLayout.tsx b/studio/components/layouts/StorageLayout/StorageLayout.tsxindex 32d3e101e50..cac7b653ae6 100644--- a/studio/components/layouts/StorageLayout/StorageLayout.tsx+++ b/studio/components/layouts/StorageLayout/StorageLayout.tsx@@ -2,9 +2,8 @@ import { FC, ReactNode, useEffect } from 'react'import { find, filter, get as _get } from 'lodash'import { observer } from 'mobx-react-lite'-import { useStore, withAuth } from 'hooks'-import { API_URL } from 'lib/constants'-import { get } from 'lib/common/fetch'+import { useProjectSettings, useStore, withAuth } from 'hooks'+import BaseLayout from 'components/layouts'import ProjectLayout from '../ProjectLayout/ProjectLayout'import StorageMenu from './StorageMenu'import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'@@ -12,6 +11,8 @@ import { formatPoliciesForStorage } from 'components/to-be-cleaned/Storage/Storaimport CreateBucketModal from 'components/to-be-cleaned/Storage/CreateBucketModal'import DeleteBucketModal from 'components/to-be-cleaned/Storage/DeleteBucketModal'import ToggleBucketPublicModal from 'components/to-be-cleaned/Storage/ToggleBucketPublicModal'+import { useRouter } from 'next/router'+import NoPermission from 'components/ui/NoPermission'interface Props {title: string@@ -20,7 +21,8 @@ interface Props {const StorageLayout: FC<Props> = ({ title, children }) => {const { ui, meta } = useStore()- const ref = ui.selectedProject?.ref+ const router = useRouter()+ const { ref } = router.queryconst storageExplorerStore = useStorageStore()const {@@ -36,40 +38,24 @@ const StorageLayout: FC<Props> = ({ title, children }) => {toggleBucketPublic,} = storageExplorerStore || {}- useEffect(() => {- if (ref) {- initializeStorageStore(ref)- }- }, [ref])+ const { services, isLoading } = useProjectSettings(ref as string | undefined)+ const apiService = find(services ?? [], (service) => service.app.id === 1)+ const projectUrl = apiService?.app_config?.endpoint ?? ''+ const serviceKey = find(apiService?.service_api_keys ?? [], (key) => key.tags === 'service_role')+ const canAccessStorage = !isLoading && services && serviceKey- const getProjectConfig = async () => {- const { services } = await get(`${API_URL}/props/project/${ref}/settings`)- const apiService = find(services, (service) => service.app.id === 1)- if (apiService) {- const projectUrl = apiService?.app_config?.endpoint ?? ''- const serviceKey = find(apiService.service_api_keys, (key) => key.tags === 'service_role')- const projectApiKey = serviceKey?.api_key ?? ''- return { projectUrl, projectApiKey }- } else {- console.error('Storage layout: Unable to find apiService')- return {}- }- }+ useEffect(() => {+ if (!isLoading && services) initializeStorageStore()+ }, [isLoading])- const initializeStorageStore = async (projectRef: any) => {- try {- const { projectUrl, projectApiKey } = await getProjectConfig()- if (projectUrl && projectApiKey) {- storageExplorerStore.initStore(projectRef, projectUrl, projectApiKey)+ const initializeStorageStore = async () => {+ if (projectUrl) {+ if (serviceKey) {+ storageExplorerStore.initStore(ref, projectUrl, serviceKey.api_key)await storageExplorerStore.fetchBuckets()- } else {- throw new Error(- `StorageLayout: Failed to getProjectConfig - ${projectUrl} ${projectApiKey}`- )}- } catch (error: any) {+ } else {ui.setNotification({- error,category: 'error',message:'Failed to fetch project configuration. Try refreshing your browser, or reach out to us at [email protected]',@@ -99,6 +85,16 @@ const StorageLayout: FC<Props> = ({ title, children }) => {}}+ if (!canAccessStorage) {+ return (+ <BaseLayout>+ <main style={{ maxHeight: '100vh' }} className="flex-1 overflow-y-auto">+ <NoPermission isFullPage resourceText="access your project's storage" />+ </main>+ </BaseLayout>+ )+ }+return (<ProjectLayout title={title || 'Storage'} product="Storage" productMenu={<StorageMenu />}>{children}