Skip to content

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

fix

Joshen Lim550712d93634
diff --git a/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.tsx b/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.tsx
index 24372391c6d..48fcd0ee1ed 100644
--- a/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.tsx
+++ b/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.tsx
@@ -1,6 +1,7 @@
import * as Tooltip from '@radix-ui/react-tooltip'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import clsx from 'clsx'
+import { useParams } from 'common'
import dayjs from 'dayjs'
import Link from 'next/link'
import { useRouter } from 'next/router'
@@ -18,7 +19,6 @@ import {
Toggle,
} from 'ui'
-import { useParams } from 'common/hooks'
import {
FormActions,
FormHeader,
@@ -29,13 +29,13 @@ import {
} from 'components/ui/Forms'
import Panel from 'components/ui/Panel'
import { useProjectApiQuery } from 'data/config/project-api-query'
+import { useCustomDomainsQuery } from 'data/custom-domains/custom-domains-query'
import { useEdgeFunctionQuery } from 'data/edge-functions/edge-function-query'
import { useEdgeFunctionDeleteMutation } from 'data/edge-functions/edge-functions-delete-mutation'
import { useEdgeFunctionUpdateMutation } from 'data/edge-functions/edge-functions-update-mutation'
import { useCheckPermissions, useStore } from 'hooks'
import CommandRender from '../CommandRender'
import { generateCLICommands } from './EdgeFunctionDetails.utils'
-import { useCustomDomainsQuery } from 'data/custom-domains/custom-domains-query'
const EdgeFunctionDetails = () => {
const router = useRouter()
diff --git a/studio/components/interfaces/Functions/TerminalInstructions.tsx b/studio/components/interfaces/Functions/TerminalInstructions.tsx
index a5b4f58b3f1..216a4c6faa7 100644
--- a/studio/components/interfaces/Functions/TerminalInstructions.tsx
+++ b/studio/components/interfaces/Functions/TerminalInstructions.tsx
@@ -7,6 +7,7 @@ import { Button, IconBookOpen, IconCode, IconMaximize2, IconMinimize2, IconTermi
import CommandRender from 'components/interfaces/Functions/CommandRender'
import { useAccessTokensQuery } from 'data/access-tokens/access-tokens-query'
import { useProjectApiQuery } from 'data/config/project-api-query'
+import { useCustomDomainsQuery } from 'data/custom-domains/custom-domains-query'
import { Commands } from './Functions.types'
interface TerminalInstructionsProps {
@@ -21,8 +22,10 @@ const TerminalInstructions = ({
const router = useRouter()
const { ref: projectRef } = useParams()
const [showInstructions, setShowInstructions] = useState(!closable)
+
const { data: tokens } = useAccessTokensQuery()
const { data: settings } = useProjectApiQuery({ projectRef })
+ const { data: customDomainData } = useCustomDomainsQuery({ projectRef })
const apiService = settings?.autoApiService
const anonKey = apiService?.service_api_keys.find((x) => x.name === 'anon key')
@@ -30,7 +33,10 @@ const TerminalInstructions = ({
: '[YOUR ANON KEY]'
const endpoint = settings?.autoApiService.app_config.endpoint ?? ''
- const functionsEndpoint = `${endpoint}/functions/v1`
+ const functionsEndpoint =
+ customDomainData?.customDomain?.status === 'active'
+ ? `https://${customDomainData.customDomain.hostname}/functions/v1`
+ : `https://${endpoint}/functions/v1`
// get the .co or .net TLD from the restUrl
const restUrl = settings?.autoApiService.restUrl
@@ -70,7 +76,7 @@ const TerminalInstructions = ({
jsx: () => {
return (
<>
- <span className="text-brand-600">curl</span> -L -X POST 'https://{functionsEndpoint}
+ <span className="text-brand-600">curl</span> -L -X POST '{functionsEndpoint}
/hello-world' -H 'Authorization: Bearer [YOUR ANON KEY]'{' '}
{`--data '{"name":"Functions"}'`}
</>
diff --git a/studio/data/edge-functions/edge-functions-query.ts b/studio/data/edge-functions/edge-functions-query.ts
index f0826e7373a..b93342b2835 100644
--- a/studio/data/edge-functions/edge-functions-query.ts
+++ b/studio/data/edge-functions/edge-functions-query.ts
@@ -3,6 +3,7 @@ import { get } from 'lib/common/fetch'
import { API_ADMIN_URL, IS_PLATFORM } from 'lib/constants'
import { useCallback } from 'react'
import { edgeFunctionsKeys } from './keys'
+import { ResponseError } from 'types'
export type EdgeFunctionsVariables = { projectRef?: string }
@@ -32,7 +33,7 @@ export async function getEdgeFunctions(
}
export type EdgeFunctionsData = Awaited<ReturnType<typeof getEdgeFunctions>>
-export type EdgeFunctionsError = unknown
+export type EdgeFunctionsError = ResponseError
export const useEdgeFunctionsQuery = <TData = EdgeFunctionsData>(
{ projectRef }: EdgeFunctionsVariables,
diff --git a/studio/pages/project/[ref]/functions/index.tsx b/studio/pages/project/[ref]/functions/index.tsx
index b19b56009a5..5f0e6b87fba 100644
--- a/studio/pages/project/[ref]/functions/index.tsx
+++ b/studio/pages/project/[ref]/functions/index.tsx
@@ -1,56 +1,65 @@
+import { useParams } from 'common'
import { observer } from 'mobx-react-lite'
-import { useParams } from 'common/hooks'
-import { NextPageWithLayout } from 'types'
-import Table from 'components/to-be-cleaned/Table'
-import FunctionsLayout from 'components/layouts/FunctionsLayout'
import { EdgeFunctionsListItem, FunctionsEmptyState } from 'components/interfaces/Functions'
-import ShimmeringLoader from 'components/ui/ShimmeringLoader'
+import FunctionsLayout from 'components/layouts/FunctionsLayout'
+import Table from 'components/to-be-cleaned/Table'
+import AlertError from 'components/ui/AlertError'
+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useEdgeFunctionsQuery } from 'data/edge-functions/edge-functions-query'
+import { NextPageWithLayout } from 'types'
const PageLayout: NextPageWithLayout = () => {
const { ref } = useParams()
- const { isLoading, data: functions } = useEdgeFunctionsQuery({ projectRef: ref })
+ const {
+ data: functions,
+ error,
+ isLoading,
+ isError,
+ isSuccess,
+ } = useEdgeFunctionsQuery({ projectRef: ref })
const hasFunctions = (functions ?? []).length > 0
- if (isLoading || functions === undefined) {
- return (
- <div className="space-y-2 w-full py-6">
- <ShimmeringLoader />
- <ShimmeringLoader className="w-3/4" />
- <ShimmeringLoader className="w-1/2" />
- </div>
- )
- }
-
- return hasFunctions ? (
- <div className="py-6 space-y-4">
- <div className="flex justify-between items-center">
- <span className="text-sm text-scale-900">{`${functions.length} function${
- functions.length > 1 ? 's' : ''
- } deployed`}</span>
- </div>
- <Table
- head={
- <>
- <Table.th>Name</Table.th>
- <Table.th>URL</Table.th>
- <Table.th className="hidden 2xl:table-cell">Created</Table.th>
- <Table.th className="lg:table-cell">Last updated</Table.th>
- <Table.th className="lg:table-cell">Deployments</Table.th>
- </>
- }
- body={
- <>
- {functions.length > 0 &&
- functions.map((item) => <EdgeFunctionsListItem key={item.id} function={item} />)}
- </>
- }
- />
+ return (
+ <div className="py-6">
+ {isLoading && <GenericSkeletonLoader />}
+ {isError && <AlertError error={error} subject="Failed to retrieve edge functions" />}
+ {isSuccess && (
+ <>
+ {hasFunctions ? (
+ <div className="py-6 space-y-4">
+ <div className="flex justify-between items-center">
+ <span className="text-sm text-scale-900">{`${functions.length} function${
+ functions.length > 1 ? 's' : ''
+ } deployed`}</span>
+ </div>
+ <Table
+ head={
+ <>
+ <Table.th>Name</Table.th>
+ <Table.th>URL</Table.th>
+ <Table.th className="hidden 2xl:table-cell">Created</Table.th>
+ <Table.th className="lg:table-cell">Last updated</Table.th>
+ <Table.th className="lg:table-cell">Deployments</Table.th>
+ </>
+ }
+ body={
+ <>
+ {functions.length > 0 &&
+ functions.map((item) => (
+ <EdgeFunctionsListItem key={item.id} function={item} />
+ ))}
+ </>
+ }
+ />
+ </div>
+ ) : (
+ <FunctionsEmptyState />
+ )}
+ </>
+ )}
</div>
- ) : (
- <FunctionsEmptyState />
)
}