diff --git a/studio/components/layouts/ProjectLayout/ConnectingState.tsx b/studio/components/layouts/ProjectLayout/ConnectingState.tsx index db284a04e88..aec6262c5db 100644 --- a/studio/components/layouts/ProjectLayout/ConnectingState.tsx +++ b/studio/components/layouts/ProjectLayout/ConnectingState.tsx @@ -37,7 +37,7 @@ const ConnectingState: FC = ({ project }) => { }, [project]) const testProjectConnection = async () => { - const result = await pingPostgrest(project.restUrl!, { + const result = await pingPostgrest(project.restUrl!, project.ref, { kpsVersion: project.kpsVersion, }) if (result) { diff --git a/studio/lib/pingPostgrest.ts b/studio/lib/pingPostgrest.ts index 169b9afd327..a324a5b1c7c 100644 --- a/studio/lib/pingPostgrest.ts +++ b/studio/lib/pingPostgrest.ts @@ -1,3 +1,4 @@ +import { String } from 'lodash' import semver from 'semver' import { headWithTimeout, getWithTimeout } from './common/fetch' import { API_URL } from './constants' @@ -16,12 +17,12 @@ import { API_URL } from './constants' */ async function pingPostgrest( restUrl: string, + projectRef: string, options?: { kpsVersion?: string timeout?: 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 @@ -41,7 +42,10 @@ async function pingPostgrest( } export default pingPostgrest -const getServiceApiKey = async (projectRef: string, timeout = DEFAULT_TIMEOUT_MILLISECONDS): Promise => { +const getServiceApiKey = async ( + projectRef: string, + timeout = DEFAULT_TIMEOUT_MILLISECONDS +): Promise => { 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 diff --git a/studio/stores/app/ProjectStore.ts b/studio/stores/app/ProjectStore.ts index 87744a165a8..028f9bc31f6 100644 --- a/studio/stores/app/ProjectStore.ts +++ b/studio/stores/app/ProjectStore.ts @@ -62,11 +62,8 @@ export default class ProjectStore extends PostgresMetaInterface { } async pingPostgrest(project: Project): Promise<'ONLINE' | 'OFFLINE' | undefined> { - if ( - project.status === PROJECT_STATUS.ACTIVE_HEALTHY && - project.restUrl - ) { - const success = await pingPostgrest(project.restUrl, { + if (project.status === PROJECT_STATUS.ACTIVE_HEALTHY && project.restUrl) { + const success = await pingPostgrest(project.restUrl, project.ref, { kpsVersion: project.kpsVersion, }) return success ? 'ONLINE' : 'OFFLINE'