From 3d51706c9fbd2e4dce7c346badcb0d85fa4e142b Mon Sep 17 00:00:00 2001 From: Terry Sutton Date: Wed, 10 Apr 2024 14:03:14 -0230 Subject: [PATCH] Add warning about disabled public schema on api page --- .../Docs/Pages/Tables/Introduction.tsx | 40 +++++++++- .../Settings/API/PostgrestConfig.tsx | 2 +- .../interfaces/Settings/API/ServiceList.tsx | 2 +- .../layouts/DocsLayout/DocsLayout.utils.tsx | 73 ++++++++++--------- 4 files changed, 77 insertions(+), 40 deletions(-) diff --git a/apps/studio/components/interfaces/Docs/Pages/Tables/Introduction.tsx b/apps/studio/components/interfaces/Docs/Pages/Tables/Introduction.tsx index 499b9709810..bd36cb24e0d 100644 --- a/apps/studio/components/interfaces/Docs/Pages/Tables/Introduction.tsx +++ b/apps/studio/components/interfaces/Docs/Pages/Tables/Introduction.tsx @@ -3,14 +3,24 @@ import Link from 'next/link' import CodeSnippet from 'components/interfaces/Docs/CodeSnippet' import GeneratingTypes from 'components/interfaces/Docs/GeneratingTypes' +import { useProjectPostgrestConfigQuery } from 'data/config/project-postgrest-config-query' +import { Alert_Shadcn_, AlertDescription_Shadcn_, AlertTitle_Shadcn_, Button } from 'ui' +import { Info } from 'lucide-react' +import ReactMarkdown from 'react-markdown' interface IntroductionProps { selectedLang: 'bash' | 'js' } const Introduction = ({ selectedLang }: IntroductionProps) => { - const { ref } = useParams() + const { ref: projectRef } = useParams() + const { data: config } = useProjectPostgrestConfigQuery({ projectRef }) + const isPublicSchemaEnabled = config?.db_schema + .split(',') + .map((name) => name.trim()) + .includes('public') + console.log({ isPublicSchemaEnabled }) return ( <>

Introduction

@@ -20,6 +30,32 @@ const Introduction = ({ selectedLang }: IntroductionProps) => { All views and tables in the public schema and accessible by the active database role for a request are available for querying.

+
+ {!isPublicSchemaEnabled && ( + + + + The `public` schema is not exposed + + + + You will not be able to query tables and views in the `public` schema via + postgREST or supabase-js. + +
+ +
+
+
+ )} +
@@ -56,7 +92,7 @@ const Introduction = ({ selectedLang }: IntroductionProps) => { If you still want to use GraphQL, you can. Supabase provides you with a full Postgres database, so as long as your middleware can connect to the database then you can still use the tools you love. You can find the database connection details{' '} - in the settings. + in the settings.

diff --git a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx index 735367e149c..c8e218635d8 100644 --- a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx +++ b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx @@ -106,7 +106,7 @@ const PostgrestConfig = () => { <> API settings

} + header="API settings" footer={
{ -
+
diff --git a/apps/studio/components/layouts/DocsLayout/DocsLayout.utils.tsx b/apps/studio/components/layouts/DocsLayout/DocsLayout.utils.tsx index 25744596a95..f3f6cf160de 100644 --- a/apps/studio/components/layouts/DocsLayout/DocsLayout.utils.tsx +++ b/apps/studio/components/layouts/DocsLayout/DocsLayout.utils.tsx @@ -32,43 +32,44 @@ export const generateDocsMenu = ( : []), ], }, - ...(flags?.isPublicSchemaEnabled - ? [ - { - title: 'Tables and Views', - items: [ - { - name: 'Introduction', - key: 'tables-intro', - url: `/project/${ref}/api?page=tables-intro`, + + { + title: 'Tables and Views', + items: [ + { + name: 'Introduction', + key: 'tables-intro', + url: `/project/${ref}/api?page=tables-intro`, + items: [], + }, + ...(flags?.isPublicSchemaEnabled + ? tables.sort().map((table) => { + return { + name: table, + key: table, + url: `/project/${ref}/api?resource=${table}`, items: [], - }, - ...tables.sort().map((table) => { - return { - name: table, - key: table, - url: `/project/${ref}/api?resource=${table}`, - items: [], - } - }), - ], - }, - { - title: 'Stored Procedures', - items: [ - { - name: 'Introduction', - key: 'rpc-intro', - url: `/project/${ref}/api?page=rpc-intro`, - items: [], - }, - ...functions.map((fn) => { - return { name: fn, key: fn, url: `/project/${ref}/api?rpc=${fn}`, items: [] } - }), - ], - }, - ] - : []), + } + }) + : []), + ], + }, + { + title: 'Stored Procedures', + items: [ + { + name: 'Introduction', + key: 'rpc-intro', + url: `/project/${ref}/api?page=rpc-intro`, + items: [], + }, + ...(flags?.isPublicSchemaEnabled + ? functions.map((fn) => { + return { name: fn, key: fn, url: `/project/${ref}/api?rpc=${fn}`, items: [] } + }) + : []), + ], + }, { title: 'GraphQL',