Skip to content

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

Refactor custom domain verification (#37349)

Joshen Lim008cca006d6d
diff --git a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainActivate.tsx b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainActivate.tsx
index c471cd49438..ef87d4d509d 100644
--- a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainActivate.tsx
+++ b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainActivate.tsx
@@ -30,7 +30,13 @@ const CustomDomainActivate = ({ projectRef, customDomain }: CustomDomainActivate
},
}
)
- const { mutate: deleteCustomDomain, isLoading: isDeleting } = useCustomDomainDeleteMutation()
+ const { mutate: deleteCustomDomain, isLoading: isDeleting } = useCustomDomainDeleteMutation({
+ onSuccess: () => {
+ toast.success(
+ 'Custom domain setup cancelled successfully. It may take a few seconds before your custom domain is fully removed, so you may need to refresh your browser.'
+ )
+ },
+ })
const endpoint = settings?.app_config?.endpoint
diff --git a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx
index 6a7e80b13f0..aa2391f660b 100644
--- a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx
+++ b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx
@@ -27,10 +27,10 @@ const CustomDomainConfig = () => {
const hasCustomDomainAddon = !!addons?.selected_addons.find((x) => x.type === 'custom_domain')
const {
+ data: customDomainData,
isLoading: isCustomDomainsLoading,
isError,
isSuccess,
- data,
} = useCustomDomainsQuery(
{ projectRef: ref },
{
@@ -45,6 +45,8 @@ const CustomDomainConfig = () => {
}
)
+ const { status, customDomain } = customDomainData || {}
+
return (
<section id="custom-domains">
<FormHeader title="Custom Domains" description="Present a branded experience to your users" />
@@ -94,24 +96,25 @@ const CustomDomainConfig = () => {
</div>
</Panel.Content>
</Panel>
- ) : data?.status === '0_no_hostname_configured' ? (
+ ) : status === '0_no_hostname_configured' ? (
<CustomDomainsConfigureHostname />
) : (
<Panel>
{isSuccess && (
<div className="flex flex-col">
- {(data.status === '1_not_started' ||
- data.status === '2_initiated' ||
- data.status === '3_challenge_verified') && (
- <CustomDomainVerify customDomain={data.customDomain} />
- )}
+ {(status === '1_not_started' ||
+ status === '2_initiated' ||
+ status === '3_challenge_verified') && <CustomDomainVerify />}
- {data.status === '4_origin_setup_completed' && (
- <CustomDomainActivate projectRef={ref} customDomain={data.customDomain} />
+ {customDomainData.status === '4_origin_setup_completed' && (
+ <CustomDomainActivate
+ projectRef={ref}
+ customDomain={customDomainData.customDomain}
+ />
)}
- {data.status === '5_services_reconfigured' && (
- <CustomDomainDelete projectRef={ref} customDomain={data.customDomain} />
+ {customDomainData.status === '5_services_reconfigured' && (
+ <CustomDomainDelete projectRef={ref} customDomain={customDomainData.customDomain} />
)}
</div>
)}
diff --git a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainDelete.tsx b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainDelete.tsx
index a029d8a1817..4ec3c264442 100644
--- a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainDelete.tsx
+++ b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainDelete.tsx
@@ -18,7 +18,9 @@ const CustomDomainDelete = ({ projectRef, customDomain }: CustomDomainDeleteProp
const [isDeleteConfirmModalVisible, setIsDeleteConfirmModalVisible] = useState(false)
const { mutate: deleteCustomDomain } = useCustomDomainDeleteMutation({
onSuccess: () => {
- toast.success(`Successfully deleted custom domain`)
+ toast.success(
+ `Successfully deleted custom domain. It may take a few seconds before your custom domain is fully removed, hence you may need to refresh your browser.`
+ )
setIsDeleteConfirmModalVisible(false)
},
})
diff --git a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx
index 9d97d93a157..2e83375d731 100644
--- a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx
+++ b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx
@@ -1,13 +1,14 @@
import { AlertCircle, HelpCircle, RefreshCw } from 'lucide-react'
import Link from 'next/link'
import { useState } from 'react'
+import { toast } from 'sonner'
import { useParams } from 'common'
import { DocsButton } from 'components/ui/DocsButton'
import Panel from 'components/ui/Panel'
import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
import { useCustomDomainDeleteMutation } from 'data/custom-domains/custom-domains-delete-mutation'
-import type { CustomDomainResponse } from 'data/custom-domains/custom-domains-query'
+import { useCustomDomainsQuery } from 'data/custom-domains/custom-domains-query'
import { useCustomDomainReverifyMutation } from 'data/custom-domains/custom-domains-reverify-mutation'
import { useInterval } from 'hooks/misc/useInterval'
import {
@@ -20,16 +21,17 @@ import {
import DNSRecord from './DNSRecord'
import { DNSTableHeaders } from './DNSTableHeaders'
-export type CustomDomainVerifyProps = {
- customDomain: CustomDomainResponse
-}
-
-const CustomDomainVerify = ({ customDomain }: CustomDomainVerifyProps) => {
+const CustomDomainVerify = () => {
const { ref: projectRef } = useParams()
const [isNotVerifiedYet, setIsNotVerifiedYet] = useState(false)
const { data: settings } = useProjectSettingsV2Query({ projectRef })
+ const { data: customDomainData } = useCustomDomainsQuery({ projectRef })
+ const customDomain = customDomainData?.customDomain
+ const isSSLCertificateDeploying =
+ customDomain?.ssl.status !== undefined && customDomain.ssl.txt_name === undefined
+
const { mutate: reverifyCustomDomain, isLoading: isReverifyLoading } =
useCustomDomainReverifyMutation({
onSuccess: (res) => {
@@ -37,13 +39,19 @@ const CustomDomainVerify = ({ customDomain }: CustomDomainVerifyProps) => {
},
})
- const { mutate: deleteCustomDomain, isLoading: isDeleting } = useCustomDomainDeleteMutation()
+ const { mutate: deleteCustomDomain, isLoading: isDeleting } = useCustomDomainDeleteMutation({
+ onSuccess: () => {
+ toast.success(
+ 'Custom domain setup cancelled successfully. It may take a few seconds before your custom domain is fully removed, so you may need to refresh your browser.'
+ )
+ },
+ })
- const hasCAAErrors = customDomain.ssl.validation_errors?.reduce(
+ const hasCAAErrors = customDomain?.ssl.validation_errors?.reduce(
(acc, error) => acc || error.message.includes('caa_error'),
false
)
- const isValidating = (customDomain.ssl.txt_name ?? '') === ''
+ const isValidating = (customDomain?.ssl.txt_name ?? '') === ''
const onReverifyCustomDomain = () => {
if (!projectRef) return console.error('Project ref is required')
@@ -53,7 +61,7 @@ const CustomDomainVerify = ({ customDomain }: CustomDomainVerifyProps) => {
useInterval(
onReverifyCustomDomain,
// Poll every 5 seconds if the SSL certificate is being deployed
- customDomain.ssl.status !== undefined && customDomain.ssl.txt_name === undefined ? 5000 : false
+ isSSLCertificateDeploying && !isDeleting ? 5000 : false
)
const onCancelCustomDomain = async () => {
@@ -67,7 +75,7 @@ const CustomDomainVerify = ({ customDomain }: CustomDomainVerifyProps) => {
<div>
<h4 className="text-foreground mb-2">
Configure TXT verification for your custom domain{' '}
- <code className="text-sm">{customDomain.hostname}</code>
+ <code className="text-sm">{customDomain?.hostname}</code>
</h4>
<p className="text-sm text-foreground-light">
Set the following TXT record(s) in your DNS provider, then click verify to confirm your
@@ -102,7 +110,7 @@ const CustomDomainVerify = ({ customDomain }: CustomDomainVerifyProps) => {
<Link
target="_blank"
rel="noreferrer"
- href={`https://whatsmydns.net/#TXT/${customDomain.hostname}`}
+ href={`https://whatsmydns.net/#TXT/${customDomain?.hostname}`}
className="text-brand"
>
here
@@ -131,13 +139,13 @@ const CustomDomainVerify = ({ customDomain }: CustomDomainVerifyProps) => {
</AlertTitle_Shadcn_>
<AlertDescription_Shadcn_>
Please add a CAA record allowing "digicert.com" to issue certificates for{' '}
- <code className="text-xs">{customDomain.hostname}</code>. For example:{' '}
+ <code className="text-xs">{customDomain?.hostname}</code>. For example:{' '}
<code className="text-xs">0 issue "digicert.com"</code>
</AlertDescription_Shadcn_>
</Alert_Shadcn_>
)}
- {customDomain.ssl.status === 'validation_timed_out' ? (
+ {customDomain?.ssl.status === 'validation_timed_out' ? (
<Alert_Shadcn_>
<WarningIcon />
<AlertTitle_Shadcn_>Validation timed out</AlertTitle_Shadcn_>
@@ -147,27 +155,27 @@ const CustomDomainVerify = ({ customDomain }: CustomDomainVerifyProps) => {
</Alert_Shadcn_>
) : (
<div className="space-y-2">
- <DNSTableHeaders display={customDomain.ssl.txt_name ?? ''} />
+ <DNSTableHeaders display={customDomain?.ssl.txt_name ?? ''} />
- {customDomain.verification_errors?.includes(
+ {customDomain?.verification_errors?.includes(
'custom hostname does not CNAME to this zone.'
) && (
<DNSRecord
type="CNAME"
- name={customDomain.hostname}
+ name={customDomain?.hostname}
value={settings?.app_config?.endpoint ?? 'Loading...'}
/>
)}
- {!isValidating && customDomain.ssl.status === 'pending_validation' && (
+ {!isValidating && customDomain?.ssl.status === 'pending_validation' && (
<DNSRecord
type="TXT"
- name={customDomain.ssl.txt_name ?? 'Loading...'}
- value={customDomain.ssl.txt_value ?? 'Loading...'}
+ name={customDomain?.ssl.txt_name ?? 'Loading...'}
+ value={customDomain?.ssl.txt_value ?? 'Loading...'}
/>
)}
- {customDomain.ssl.status === 'pending_deployment' && (
+ {customDomain?.ssl.status === 'pending_deployment' && (
<div className="flex items-center justify-center space-x-2 py-8">
<AlertCircle size={16} strokeWidth={1.5} />
<p className="text-sm text-foreground-light">