import { useParams } from 'common' import { AlertCircle, RefreshCw } from 'lucide-react' import { useEffect } from 'react' import { toast } from 'sonner' import { Alert, AlertDescription, AlertTitle, Button, WarningIcon } from 'ui' import { Admonition } from 'ui-patterns/admonition' import { DNSRecord } from './DNSRecord' import { DNSTableHeaders } from './DNSTableHeaders' import { DocsButton } from '@/components/ui/DocsButton' import { InlineLink } from '@/components/ui/InlineLink' 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 { useCustomDomainsQuery } from '@/data/custom-domains/custom-domains-query' import { useCustomDomainReverifyQuery } from '@/data/custom-domains/custom-domains-reverify-query' import { DOCS_URL } from '@/lib/constants' export const CustomDomainVerify = () => { const { ref: projectRef } = useParams() 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: deleteCustomDomain, isPending: 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 { data: reverifyData, refetch: refetchReverify, isFetching: isReverifyLoading, isError: isReverifyError, error: reverifyError, } = useCustomDomainReverifyQuery( { projectRef }, { // Poll every 10 seconds if the SSL certificate is being deployed refetchInterval: isSSLCertificateDeploying && !isDeleting ? 10000 : false, } ) useEffect(() => { if (isReverifyError) { toast.error(reverifyError?.message) } }, [isReverifyError, reverifyError]) const isNotVerifiedYet = reverifyData?.status === '2_initiated' const hasCAAErrors = customDomain?.ssl.validation_errors?.reduce( (acc, error) => acc || error.message.includes('caa_error'), false ) const isValidating = (customDomain?.ssl.txt_name ?? '') === '' const onReverifyCustomDomain = () => { if (!projectRef) return console.error('Project ref is required') refetchReverify() } const onCancelCustomDomain = async () => { if (!projectRef) return console.error('Project ref is required') deleteCustomDomain({ projectRef }) } return ( <>

Configure TXT verification for your custom domain{' '} {customDomain?.hostname}

Set the following TXT record(s) in your DNS provider, then click verify to confirm your control over the domain. Records which have been successfully verified will be removed from this list below.

{!isValidating && (

You may also visit{' '} here {' '} to check if your DNS has been propagated successfully before clicking verify.

{isNotVerifiedYet && (

Some registrars will require you to remove the domain name when creating DNS records. As an example, to create a record for{' '} foo.app.example.com, you would need to create an entry for foo.app.

)}
)}
{hasCAAErrors && ( Certificate Authority Authentication (CAA) error Please add a CAA record allowing "digicert.com" to issue certificates for{' '} {customDomain?.hostname}. For example:{' '} 0 issue "digicert.com" )} {customDomain?.ssl.status === 'validation_timed_out' ? ( Validation timed out Please click "Verify" again to retry the validation of the records ) : (
{customDomain?.verification_errors?.includes( 'custom hostname does not CNAME to this zone.' ) && ( )} {!isValidating && customDomain?.ssl.status === 'pending_validation' && ( )} {customDomain?.ssl.status === 'pending_deployment' && (

SSL certificate is being deployed. Please wait a few minutes and try again.

)}
)}
) }