Skip to content

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

cleans up custom domains flow

Alaister Young75ca51eff4e8
diff --git a/studio/components/interfaces/Settings/API/CustomDomainConfig.tsx b/studio/components/interfaces/Settings/API/CustomDomainConfig.tsx
index 15ea58b416c..84d89fc4713 100644
--- a/studio/components/interfaces/Settings/API/CustomDomainConfig.tsx
+++ b/studio/components/interfaces/Settings/API/CustomDomainConfig.tsx
@@ -1,3 +1,4 @@
+import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
import {
FormActions,
FormPanel,
@@ -12,7 +13,10 @@ import { useCustomDomainCreateMutation } from 'data/custom-domains/custom-domain
import { useCustomDomainsQuery } from 'data/custom-domains/custom-domains-query'
import { useCustomDomainReverifyMutation } from 'data/custom-domains/custom-domains-reverify-mutation'
import { useParams, useStore } from 'hooks'
-import { Alert, Button, Form, IconAlertCircle, IconCloudLightning, IconRefreshCw, Input } from 'ui'
+import { observer } from 'mobx-react-lite'
+import Link from 'next/link'
+import { useState } from 'react'
+import { Alert, Button, Form, IconAlertCircle, IconRefreshCw, Input } from 'ui'
import * as yup from 'yup'
const FORM_ID = 'custom-domains-form'
@@ -43,6 +47,8 @@ const CustomDomainConfig = () => {
}
)
+ console.log(data)
+
const isLoading = isSettingsLoading || isCustomDomainsLoading
const isNoHostnameConfiguredError =
@@ -50,7 +56,12 @@ const CustomDomainConfig = () => {
(error as any)?.code === 400 &&
(error as any)?.message?.includes('custom hostname configuration')
- const isUnknownError = isError && !isNoHostnameConfiguredError
+ const isNotAllowedError =
+ isError &&
+ (error as any)?.code === 400 &&
+ (error as any)?.message?.includes('not allowed to set up custom domain')
+
+ const isUnknownError = isError && !isNoHostnameConfiguredError && !isNotAllowedError
const { mutateAsync: createCustomDomain } = useCustomDomainCreateMutation()
@@ -60,14 +71,15 @@ const CustomDomainConfig = () => {
}
try {
- const something = await createCustomDomain({
+ await createCustomDomain({
projectRef: ref,
customDomain: values.domain,
})
-
- console.log('something:', something)
- } catch (error) {
- console.log('asf error:', error)
+ } catch (error: any) {
+ ui.setNotification({
+ category: 'error',
+ message: error.message,
+ })
}
}
@@ -82,15 +94,24 @@ const CustomDomainConfig = () => {
reverifyCustomDomain({ projectRef: ref })
}
- const { mutate: activateCustomDomain, isLoading: isActivateLoading } =
+ const [isActivateConfirmModalVisible, setIsActivateConfirmModalVisible] = useState(false)
+
+ const { mutateAsync: activateCustomDomain, isLoading: isActivateLoading } =
useCustomDomainActivateMutation()
- const onActivateCustomDomain = () => {
+ const onActivateCustomDomain = async () => {
if (!ref) {
throw new Error('Project ref is required')
}
- activateCustomDomain({ projectRef: ref })
+ try {
+ await activateCustomDomain({ projectRef: ref })
+ } catch (error: any) {
+ ui.setNotification({
+ category: 'error',
+ message: error.message,
+ })
+ }
}
if (isNoHostnameConfiguredError) {
@@ -162,79 +183,183 @@ const CustomDomainConfig = () => {
<Panel.Content className="space-y-6 border-t border-panel-border-interior-light dark:border-panel-border-interior-dark">
{isLoading && <div>Loading...</div>}
+ {isNotAllowedError && (
+ <div className="flex items-center justify-center space-x-2 py-8">
+ <IconAlertCircle size={16} strokeWidth={1.5} />
+ <p className="text-sm text-scale-1100">
+ Custom domains are not enabled for this project. Please{' '}
+ <Link href={`/support/new?ref=${ref}&category=sales`}>
+ <a className="underline">contact support</a>
+ </Link>{' '}
+ if you would like to enable this feature.
+ </p>
+ </div>
+ )}
+
{isUnknownError && (
<div className="flex items-center justify-center space-x-2 py-8">
<IconAlertCircle size={16} strokeWidth={1.5} />
<p className="text-sm text-scale-1100">
- Failed to retrieve custom domain configuration
+ Failed to retrieve custom domain configuration. Please try again later or{' '}
+ <Link href={`/support/new?ref=${ref}&category=sales`}>
+ <a className="underline">contact support</a>
+ </Link>
+ .
</p>
</div>
)}
{isSuccess && (
- <div className="flex flex-col">
- {data.customDomain.verification_errors?.includes(
- 'custom hostname does not CNAME to this zone.'
- ) && (
+ <div className="flex flex-col gap-6">
+ {data.status === '2_initiated' && (
<div>
- cname {data.customDomain.hostname}: {settings?.autoApiService.app_config.endpoint}
+ <h4 className="text-scale-1200">
+ Set the following record(s) to your DNS provider:
+ </h4>
+ <span className="text-sm text-scale-1100">
+ Please note that it may take up to 24 hours for the DNS records to propagate.
+ </span>
</div>
)}
- {data.customDomain.ownership_verification && (
- <div>
- {data.customDomain.ownership_verification.type} -{' '}
- {data.customDomain.ownership_verification.name}:{' '}
- {data.customDomain.ownership_verification.value}
- </div>
- )}
+ {(data.status === '2_initiated' || data.status === '3_challenge_verified') &&
+ data.customDomain.verification_errors?.includes(
+ 'custom hostname does not CNAME to this zone.'
+ ) && (
+ <DNSRecord
+ type="CNAME"
+ name={data.customDomain.hostname}
+ value={settings?.autoApiService.app_config.endpoint ?? 'Loading...'}
+ />
+ )}
- {data.customDomain.ssl.status === 'pending_validation' && (
- <div>
- txt {data.customDomain.ssl.txt_name}: {data.customDomain.ssl.txt_value}
- </div>
- )}
+ {(data.status === '2_initiated' || data.status === '3_challenge_verified') &&
+ data.customDomain.ownership_verification && (
+ <DNSRecord
+ type={data.customDomain.ownership_verification.type}
+ name={data.customDomain.ownership_verification.name}
+ value={data.customDomain.ownership_verification.value}
+ />
+ )}
- <Button
- icon={<IconRefreshCw />}
- onClick={onReverifyCustomDomain}
- loading={isReverifyLoading}
- >
- Verify
- </Button>
+ {(data.status === '2_initiated' || data.status === '3_challenge_verified') &&
+ data.customDomain.ssl.status === 'pending_validation' && (
+ <DNSRecord
+ type="TXT"
+ name={data.customDomain.ssl.txt_name ?? 'Loading...'}
+ value={data.customDomain.ssl.txt_value ?? 'Loading...'}
+ />
+ )}
- {data.status === '4_origin_setup_completed' && (
+ {(data.status === '2_initiated' || data.status === '3_challenge_verified') && (
<Button
- icon={
- <svg
- xmlns="http://www.w3.org/2000/svg"
- fill="none"
- viewBox="0 0 24 24"
- strokeWidth={1}
- stroke="currentColor"
- className="w-4 h-4"
- >
- <path
- strokeLinecap="round"
- strokeLinejoin="round"
- d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z"
- />
- </svg>
- }
- onClick={onActivateCustomDomain}
- loading={isActivateLoading}
+ icon={<IconRefreshCw />}
+ onClick={onReverifyCustomDomain}
+ loading={isReverifyLoading}
+ className="self-end"
>
- Activate
+ Verify
</Button>
)}
+
+ {data.status === '4_origin_setup_completed' && (
+ <div className="flex flex-col items-start gap-6">
+ <div className="flex flex-col gap-1">
+ <h4 className="text-scale-1200">
+ Setup complete! Press activate to enable {data.customDomain.hostname} for this
+ project.
+ </h4>
+
+ <span className="text-sm text-scale-1100">
+ Supabase recommends that your schedule a downtime window of 20-30 minutes for
+ your application, as you will need to update any client code (e.g., frontends,
+ mobile apps), and any OAuth providers (e.g., google, github) that use the
+ current supabase subdomain.
+ </span>
+ </div>
+
+ <Button
+ icon={
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ strokeWidth={1}
+ stroke="currentColor"
+ className="w-4 h-4"
+ >
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z"
+ />
+ </svg>
+ }
+ onClick={() => setIsActivateConfirmModalVisible(true)}
+ className="self-end"
+ >
+ Activate
+ </Button>
+ </div>
+ )}
</div>
)}
</Panel.Content>
</Panel>
- {/* Add modals here */}
+ <ConfirmModal
+ danger
+ visible={isActivateConfirmModalVisible}
+ title={`Are you sure you want to activate ${
+ data?.customDomain.hostname ?? 'your custom hostname'
+ }?`}
+ description="Your existing supabase will be deactivated."
+ buttonLabel="Activate"
+ buttonLoadingLabel="Activating"
+ onSelectCancel={() => setIsActivateConfirmModalVisible(false)}
+ onSelectConfirm={onActivateCustomDomain}
+ />
</>
)
}
-export default CustomDomainConfig
+export default observer(CustomDomainConfig)
+
+type DNSRecordProps = {
+ type: string
+ name: string
+ value: string
+}
+
+const DNSRecord = ({ type, name, value }: DNSRecordProps) => {
+ return (
+ <div className="flex gap-4">
+ <Input
+ label="Type"
+ readOnly
+ disabled
+ className="input-mono"
+ value={type.toUpperCase()}
+ layout="vertical"
+ />
+ <Input
+ label="Name"
+ readOnly
+ copy
+ disabled
+ className="input-mono flex-1"
+ value={name}
+ layout="vertical"
+ />
+ <Input
+ label="Value"
+ readOnly
+ copy
+ disabled
+ className="input-mono flex-1"
+ value={value}
+ layout="vertical"
+ />
+ </div>
+ )
+}
diff --git a/studio/data/custom-domains/custom-domains-create-mutation.ts b/studio/data/custom-domains/custom-domains-create-mutation.ts
index a5c414d773f..689ed60af47 100644
--- a/studio/data/custom-domains/custom-domains-create-mutation.ts
+++ b/studio/data/custom-domains/custom-domains-create-mutation.ts
@@ -25,7 +25,7 @@ export async function createCustomDomain({
throw response.error
}
- return { customDomain }
+ return response
}
type CustomDomainCreateData = Awaited<ReturnType<typeof createCustomDomain>>