import { AlertCircle, HelpCircle, RefreshCw } from 'lucide-react' import Link from 'next/link' import { useState } from 'react' 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 { useCustomDomainReverifyMutation } from 'data/custom-domains/custom-domains-reverify-mutation' import { useInterval } from 'hooks/misc/useInterval' import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button, WarningIcon, } from 'ui' import DNSRecord from './DNSRecord' import { DNSTableHeaders } from './DNSTableHeaders' export type CustomDomainVerifyProps = { customDomain: CustomDomainResponse } const CustomDomainVerify = ({ customDomain }: CustomDomainVerifyProps) => { const { ref: projectRef } = useParams() const [isNotVerifiedYet, setIsNotVerifiedYet] = useState(false) const { data: settings } = useProjectSettingsV2Query({ projectRef }) const { mutate: reverifyCustomDomain, isLoading: isReverifyLoading } = useCustomDomainReverifyMutation({ onSuccess: (res) => { if (res.status === '2_initiated') setIsNotVerifiedYet(true) }, }) const { mutate: deleteCustomDomain, isLoading: isDeleting } = useCustomDomainDeleteMutation() 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') reverifyCustomDomain({ projectRef }) } useInterval( onReverifyCustomDomain, // Poll every 5 seconds if the SSL certificate is being deployed customDomain.ssl.status !== undefined && customDomain.ssl.txt_name === undefined ? 5000 : false ) 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 && (
{isNotVerifiedYet ? ( ) : ( )} {isNotVerifiedYet ? 'Unable to verify records from DNS provider yet.' : 'Please note that it may take up to 24 hours for the DNS records to propagate.'}
{isNotVerifiedYet && (

Please check again soon. Note that it may take up to 24 hours for changes in DNS records to propagate.

)}

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.

)}
)}
) } export default CustomDomainVerify