import Link from 'next/link' import { useState } from 'react' import toast from 'react-hot-toast' import Panel from 'components/ui/Panel' import { useProjectApiQuery } from 'data/config/project-api-query' import { useCheckCNAMERecordMutation } from 'data/custom-domains/check-cname-mutation' import { useCustomDomainActivateMutation } from 'data/custom-domains/custom-domains-activate-mutation' import { useCustomDomainDeleteMutation } from 'data/custom-domains/custom-domains-delete-mutation' import type { CustomDomainResponse } from 'data/custom-domains/custom-domains-query' import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button, IconAlertCircle, IconExternalLink, Modal, } from 'ui' import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal' export type CustomDomainActivateProps = { projectRef?: string customDomain: CustomDomainResponse } const CustomDomainActivate = ({ projectRef, customDomain }: CustomDomainActivateProps) => { const [isActivateConfirmModalVisible, setIsActivateConfirmModalVisible] = useState(false) const { data: settings } = useProjectApiQuery({ projectRef }) const { mutate: checkCNAMERecord, isLoading: isCheckingRecord } = useCheckCNAMERecordMutation() const { mutate: activateCustomDomain, isLoading: isActivating } = useCustomDomainActivateMutation( { onSuccess: () => { toast.success(`Successfully activated custom domain`) setIsActivateConfirmModalVisible(false) }, } ) const { mutate: deleteCustomDomain, isLoading: isDeleting } = useCustomDomainDeleteMutation() const endpoint = settings?.autoApiService.endpoint const onActivateCustomDomain = async () => { if (!projectRef) return console.error('Project ref is required') checkCNAMERecord( { domain: customDomain.hostname }, { onSuccess: () => activateCustomDomain({ projectRef }) } ) } const onCancelCustomDomain = async () => { if (!projectRef) return console.error('Project ref is required') deleteCustomDomain({ projectRef }) } return ( <>

Setup complete! Press activate to enable the custom domain{' '} {customDomain.hostname} for this project.

We recommend that you schedule a downtime window of 20 - 30 minutes for your application, as you will need to update any services that need to know about your custom domain (e.g client side code or OAuth providers)
Remember to restore the original CNAME record from the first step before activating

Set up a CNAME record for {customDomain.hostname} , resolving to{' '} {endpoint ? ( {endpoint} ) : ( "your project's API URL" )} , with as low a TTL as possible. If you're using Cloudflare as your DNS provider, disable the proxy option.

Are you sure you want to activate the custom domain{' '} {customDomain.hostname} for the project? } confirmLabel="Activate" confirmLabelLoading="Activating" onCancel={() => setIsActivateConfirmModalVisible(false)} onConfirm={onActivateCustomDomain} >

This will activate the custom domain {customDomain.hostname}. Your project's Supabase domain will also remain active.

) } export default CustomDomainActivate