Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: typo autoApiService in project/[ref]/api (#11945)

Ruggero Tomaselli123d70423c36
diff --git a/studio/components/interfaces/Functions/TerminalInstructions.tsx b/studio/components/interfaces/Functions/TerminalInstructions.tsx
index 33e39092b85..dbb81db4061 100644
--- a/studio/components/interfaces/Functions/TerminalInstructions.tsx
+++ b/studio/components/interfaces/Functions/TerminalInstructions.tsx
@@ -25,7 +25,7 @@ const TerminalInstructions: FC<Props> = ({ closable = false }) => {
// Get the API service
const apiService = settings?.autoApiService
const anonKey = apiService?.service_api_keys.find((x: any) => x.name === 'anon key')
- ? apiService?.defaultApiKey
+ ? apiService.defaultApiKey
: undefined
const endpoint = apiService?.endpoint ?? ''
diff --git a/studio/pages/project/[ref]/api/index.tsx b/studio/pages/project/[ref]/api/index.tsx
index 9bad3b62f70..4a793b45190 100644
--- a/studio/pages/project/[ref]/api/index.tsx
+++ b/studio/pages/project/[ref]/api/index.tsx
@@ -5,13 +5,13 @@ import { FC, createContext, useContext, useEffect, useState } from 'react'
import { observer, useLocalObservable } from 'mobx-react-lite'
import { NextPageWithLayout } from 'types'
-import { API_URL } from 'lib/constants'
import { checkPermissions, useStore } from 'hooks'
import { get } from 'lib/common/fetch'
import { snakeToCamel } from 'lib/helpers'
import { DocsLayout } from 'components/layouts'
import { GeneralContent, ResourceContent, RpcContent } from 'components/interfaces/Docs'
import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { useProjectSettingsQuery } from 'data/config/project-settings-query'
const PageContext = createContext(null)
@@ -70,9 +70,11 @@ const DocView: FC<any> = observer(({}) => {
const [selectedLang, setSelectedLang] = useState<any>('js')
const [showApiKey, setShowApiKey] = useState<any>(DEFAULT_KEY)
- const { data, error }: any = useSWR(`${API_URL}/props/project/${PageState.projectRef}/api`, get)
- const API_KEY = data?.autoApiService?.defaultApiKey
- const swaggerUrl = data?.autoApiService?.restUrl
+ const { data, error } = useProjectSettingsQuery({ projectRef: PageState.projectRef as string })
+ const API_KEY = data?.autoApiService.service_api_keys.find((key: any) => key.tags === 'anon')
+ ? data.autoApiService.defaultApiKey
+ : undefined
+ const swaggerUrl = data?.autoApiService.restUrl
const headers: any = { apikey: API_KEY }
const canReadServiceKey = checkPermissions(
@@ -80,7 +82,7 @@ const DocView: FC<any> = observer(({}) => {
'service_api_keys.service_role_key'
)
- if (API_KEY?.length > 40) headers['Authorization'] = `Bearer ${API_KEY}`
+ if (API_KEY) headers['Authorization'] = `Bearer ${API_KEY}`
const { data: jsonSchema, error: jsonSchemaError } = useSWR(
() => swaggerUrl,
@@ -116,7 +118,7 @@ const DocView: FC<any> = observer(({}) => {
// Data Loaded
const autoApiService = {
...data.autoApiService,
- endpoint: `${data.apiService.protocol ?? 'https'}://${data.apiService.endpoint ?? '-'}`,
+ endpoint: `${data.autoApiService.protocol ?? 'https'}://${data.autoApiService.endpoint ?? '-'}`,
}
const { query } = router
@@ -172,7 +174,7 @@ const DocView: FC<any> = observer(({}) => {
key="anon"
onClick={() =>
setShowApiKey({
- key: autoApiService?.defaultApiKey,
+ key: API_KEY,
name: 'anon (public)',
})
}
@@ -184,7 +186,7 @@ const DocView: FC<any> = observer(({}) => {
key="service"
onClick={() =>
setShowApiKey({
- key: autoApiService?.serviceApiKey,
+ key: autoApiService.serviceApiKey,
name: 'service_role (secret)',
})
}
diff --git a/studio/pages/project/[ref]/functions/[id]/details.tsx b/studio/pages/project/[ref]/functions/[id]/details.tsx
index e668b4903a6..248434f9d84 100644
--- a/studio/pages/project/[ref]/functions/[id]/details.tsx
+++ b/studio/pages/project/[ref]/functions/[id]/details.tsx
@@ -99,9 +99,8 @@ const PageLayout: NextPageWithLayout = () => {
// Get the API service
const { data: settings } = useProjectSettingsQuery({ projectRef: ref as string })
const apiService = settings?.autoApiService
- const apiKeys = apiService?.service_api_keys ?? []
- const anonKey = apiKeys.find((x: any) => x.name === 'anon key')
- ? apiService?.defaultApiKey
+ const anonKey = apiService?.service_api_keys.find((x: any) => x.name === 'anon key')
+ ? apiService.defaultApiKey
: undefined
const endpoint = apiService?.endpoint ?? ''