The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
use serviceApiKey instead of internalApiKey
Bobbie Soedirgodcc76b748252
diff --git a/studio/components/layouts/ProjectLayout/ConnectingState.tsx b/studio/components/layouts/ProjectLayout/ConnectingState.tsxindex 9c1908e8d18..db284a04e88 100644--- a/studio/components/layouts/ProjectLayout/ConnectingState.tsx+++ b/studio/components/layouts/ProjectLayout/ConnectingState.tsx@@ -26,7 +26,7 @@ const ConnectingState: FC<Props> = ({ project }) => {}, [])useEffect(() => {- if (!project.restUrl || !project.internalApiKey) return+ if (!project.restUrl) return// Check project connection status every 4 seconds// pingPostgrest timeouts in 2s, wait for another 2s before checking again@@ -37,7 +37,7 @@ const ConnectingState: FC<Props> = ({ project }) => {}, [project])const testProjectConnection = async () => {- const result = await pingPostgrest(project.restUrl!, project.internalApiKey!, {+ const result = await pingPostgrest(project.restUrl!, {kpsVersion: project.kpsVersion,})if (result) {diff --git a/studio/lib/pingPostgrest.ts b/studio/lib/pingPostgrest.tsindex 8778ea5b06d..169b9afd327 100644--- a/studio/lib/pingPostgrest.ts+++ b/studio/lib/pingPostgrest.ts@@ -1,5 +1,6 @@import semver from 'semver'import { headWithTimeout, getWithTimeout } from './common/fetch'+import { API_URL } from './constants'/*** Ping Postgrest for health check. Default timeout in 2s.@@ -15,12 +16,16 @@ import { headWithTimeout, getWithTimeout } from './common/fetch'*/async function pingPostgrest(restUrl: string,- apikey: string,options?: {kpsVersion?: stringtimeout?: number}) {+ const projectRef = restUrl.match(/https:\/\/(\w+)\.supabase\./)?.[1]+ if (projectRef === undefined) return false+ const serviceApiKey = await getServiceApiKey(projectRef, options?.timeout)+ if (serviceApiKey === undefined) return false+const { kpsVersion, timeout } = options ?? {}const healthCheckApiEnable = semver.gte(// @ts-ignore@@ -29,13 +34,19 @@ async function pingPostgrest()if (healthCheckApiEnable) {const healthCheckUrl = `${restUrl.replace('/rest/', '/rest-admin/')}live`- return pingHealthCheckApi(healthCheckUrl, apikey, timeout)+ return pingHealthCheckApi(healthCheckUrl, serviceApiKey, timeout)}- return pingOpenApi(restUrl, apikey, timeout)+ return pingOpenApi(restUrl, serviceApiKey, timeout)}export default pingPostgrest+const getServiceApiKey = async (projectRef: string, timeout = DEFAULT_TIMEOUT_MILLISECONDS): Promise<string | undefined> => {+ const response = await getWithTimeout(`${API_URL}/props/project/${projectRef}/api`, { timeout })+ if (response.error || response.autoApiService.service_api_keys.length === 0) return undefined+ return response.autoApiService.serviceApiKey+}+const DEFAULT_TIMEOUT_MILLISECONDS = 2000/**diff --git a/studio/pages/api/projects/[ref]/index.ts b/studio/pages/api/projects/[ref]/index.tsindex 83aedce1b06..5d0e34ff354 100644--- a/studio/pages/api/projects/[ref]/index.ts+++ b/studio/pages/api/projects/[ref]/index.ts@@ -35,7 +35,6 @@ const handleGet = async (req: NextApiRequest, res: NextApiResponse) => {}),kpsVersion: 'kps-v1.0.0',restUrl: process.env.SUPABASE_REST_URL || 'http://localhost:8000/rest/v1/',- internalApiKey: process.env.SUPABASE_ANON_KEY,}return res.status(200).json(response)diff --git a/studio/pages/api/props/project/[ref]/api.ts b/studio/pages/api/props/project/[ref]/api.tsindex 0f0cd019722..556f4deb40b 100644--- a/studio/pages/api/props/project/[ref]/api.ts+++ b/studio/pages/api/props/project/[ref]/api.ts@@ -45,7 +45,6 @@ const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {restUrl: process.env.SUPABASE_REST_URL || 'http://localhost:8000/rest/v1/',defaultApiKey: process.env.SUPABASE_ANON_KEY,serviceApiKey: process.env.SUPABASE_SERVICE_KEY,- internalApiKey: process.env.SUPABASE_ANON_KEY,service_api_keys: [{api_key_encrypted: '-',@@ -75,7 +74,6 @@ const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {restUrl: process.env.SUPABASE_REST_URL,defaultApiKey: process.env.SUPABASE_ANON_KEY,serviceApiKey: process.env.SUPABASE_SERVICE_KEY,- internalApiKey: process.env.SUPABASE_ANON_KEY,service_api_keys: [{api_key_encrypted: '-',diff --git a/studio/pages/project/[ref]/api/index.tsx b/studio/pages/project/[ref]/api/index.tsxindex 6653b8d1d3f..502bd1521d5 100644--- a/studio/pages/project/[ref]/api/index.tsx+++ b/studio/pages/project/[ref]/api/index.tsx@@ -78,7 +78,7 @@ const DocView: FC<any> = observer(({}) => {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?.internalApiKey+ const API_KEY = data?.autoApiService?.serviceApiKeyconst swaggerUrl = data?.autoApiService?.restUrlconst headers: any = { apikey: API_KEY }diff --git a/studio/stores/app/ProjectStore.ts b/studio/stores/app/ProjectStore.tsindex 6c972a972ac..87744a165a8 100644--- a/studio/stores/app/ProjectStore.ts+++ b/studio/stores/app/ProjectStore.ts@@ -64,10 +64,9 @@ export default class ProjectStore extends PostgresMetaInterface<Project> {async pingPostgrest(project: Project): Promise<'ONLINE' | 'OFFLINE' | undefined> {if (project.status === PROJECT_STATUS.ACTIVE_HEALTHY &&- project.restUrl &&- project.internalApiKey+ project.restUrl) {- const success = await pingPostgrest(project.restUrl, project.internalApiKey, {+ const success = await pingPostgrest(project.restUrl, {kpsVersion: project.kpsVersion,})return success ? 'ONLINE' : 'OFFLINE'diff --git a/studio/stores/pgmeta/OpenApiStore.ts b/studio/stores/pgmeta/OpenApiStore.tsindex be5e2a29847..277e0619d24 100644--- a/studio/stores/pgmeta/OpenApiStore.ts+++ b/studio/stores/pgmeta/OpenApiStore.ts@@ -53,7 +53,7 @@ export default class OpenApiStore implements IOpenApiStore {const projectConfig = await get(this.url, { headers })if (projectConfig.error) throw projectConfig.error- const apiKey = projectConfig.autoApiService?.internalApiKey+ const apiKey = projectConfig.autoApiService?.serviceApiKeyconst restApiUrl = projectConfig.autoApiService?.restUrlconst response = await get<OpenAPIV2.Document>(`${restApiUrl}?apikey=${apiKey}`, {diff --git a/studio/types/base.ts b/studio/types/base.tsindex a99454c52ee..c28a96106b9 100644--- a/studio/types/base.ts+++ b/studio/types/base.ts@@ -23,7 +23,6 @@ export interface Project extends ProjectBase {// available after projects.fetchDetailconnectionString?: stringkpsVersion?: string- internalApiKey?: stringrestUrl?: string// store subscription tier products.metadata.supabase_prod_idsubscription_tier?: string