Files
supabase/apps/studio/data/config/project-endpoint-query.ts
Ali Waseem bc23782d0b fix: update project unpause to not show undefined (#43820)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

When un-pausing the dashboard, the project home page on platform shows
undefined rather than the default state of "URL not available"

## Ways to test

You can pause and then unpause a project to see if this works correctly
2026-03-16 14:39:56 -06:00

55 lines
2.2 KiB
TypeScript

import { IS_PLATFORM } from 'common'
import { useProjectSettingsV2Query } from './project-settings-v2-query'
import { useCustomDomainsQuery } from '@/data/custom-domains/custom-domains-query'
import { useProjectAddonsQuery } from '@/data/subscriptions/project-addons-query'
export const useProjectApiUrl = (
{ projectRef }: { projectRef?: string },
{ enabled = true }: { enabled?: boolean } = {}
) => {
const { data } = useProjectAddonsQuery({ projectRef })
const hasCustomDomainsAddon = !!data?.selected_addons.find((x) => x.type === 'custom_domain')
const {
data: customDomainData,
error: customDomainsError,
isPending: isLoadingCustomDomains,
isSuccess: isSuccessCustomDomains,
isError: isErrorCustomDomains,
} = useCustomDomainsQuery({ projectRef }, { enabled })
const isCustomDomainsActive = customDomainData?.customDomain?.status === 'active'
const customEndpoint =
hasCustomDomainsAddon && isCustomDomainsActive
? `https://${customDomainData?.customDomain?.hostname}`
: undefined
const {
data: settings,
error: projectSettingsError,
isPending: isLoadingProjectSettings,
isSuccess: isSuccessProjectSettings,
isError: isErrorProjectSettings,
} = useProjectSettingsV2Query({ projectRef }, { enabled })
const protocol = settings?.app_config?.protocol ?? 'https'
const endpoint = settings?.app_config?.endpoint
const hostEndpoint =
isSuccessProjectSettings && endpoint ? `${protocol}://${endpoint}` : undefined
const resolvedEndpoint = isCustomDomainsActive ? customEndpoint : hostEndpoint
const storageEndpoint = settings?.app_config?.storage_endpoint
? `${IS_PLATFORM ? 'https' : protocol}://${settings?.app_config?.storage_endpoint}`
: undefined
return {
data: resolvedEndpoint,
customEndpoint,
hostEndpoint,
storageEndpoint,
error: projectSettingsError || (hasCustomDomainsAddon ? customDomainsError : undefined),
isPending: isLoadingProjectSettings || (hasCustomDomainsAddon && isLoadingCustomDomains),
isSuccess: isSuccessProjectSettings && (!hasCustomDomainsAddon || isSuccessCustomDomains),
isError: isErrorProjectSettings || (hasCustomDomainsAddon && isErrorCustomDomains),
}
}