The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Enforce CNAME record check prior to activating custom domain
Joshen Lim6c12fc04584e
diff --git a/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainActivate.tsx b/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainActivate.tsxindex 5eea2a0bb4d..2c79b3f2164 100644--- a/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainActivate.tsx+++ b/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainActivate.tsx@@ -1,14 +1,24 @@+import { observer } from 'mobx-react-lite'import Link from 'next/link'import { useState } from 'react'-import { observer } from 'mobx-react-lite'-import { Button, IconExternalLink } from 'ui'+import {+ AlertDescription_Shadcn_,+ AlertTitle_Shadcn_,+ Alert_Shadcn_,+ Button,+ IconAlertCircle,+ IconExternalLink,+ Modal,+} from 'ui'-import { useStore } from 'hooks'-import { useCustomDomainDeleteMutation } from 'data/custom-domains/custom-domains-delete-mutation'+import ConfirmationModal from 'components/ui/ConfirmationModal'+import Panel from 'components/ui/Panel'+import { useProjectApiQuery } from 'data/config/project-api-query'import { useCustomDomainActivateMutation } from 'data/custom-domains/custom-domains-activate-mutation'+import { useCustomDomainDeleteMutation } from 'data/custom-domains/custom-domains-delete-mutation'import { CustomDomainResponse } from 'data/custom-domains/custom-domains-query'-import Panel from 'components/ui/Panel'-import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'+import { useStore } from 'hooks'+import { verifyCNAME } from './CustomDomainConfig.utils'export type CustomDomainActivateProps = {projectRef?: string@@ -17,8 +27,10 @@ export type CustomDomainActivateProps = {const CustomDomainActivate = ({ projectRef, customDomain }: CustomDomainActivateProps) => {const { ui } = useStore()+ const [isActivating, setIsActivating] = useState(false)const [isActivateConfirmModalVisible, setIsActivateConfirmModalVisible] = useState(false)+ const { data: settings } = useProjectApiQuery({ projectRef })const { mutate: activateCustomDomain } = useCustomDomainActivateMutation({onSuccess: () => {ui.setNotification({ category: 'success', message: `Successfully activated custom domain` })@@ -27,9 +39,32 @@ const CustomDomainActivate = ({ projectRef, customDomain }: CustomDomainActivate})const { mutate: deleteCustomDomain, isLoading: isDeleting } = useCustomDomainDeleteMutation()+ const endpoint = settings?.autoApiService.endpoint+const onActivateCustomDomain = async () => {if (!projectRef) return console.error('Project ref is required')- activateCustomDomain({ projectRef })++ setIsActivating(true)++ const cnameVerified = await verifyCNAME(customDomain.hostname)+ if (!cnameVerified) {+ setIsActivating(false)+ return ui.setNotification({+ category: 'error',+ message: `Your CNAME record for ${customDomain.hostname} cannot be found - if you've just added the CNAME record, do check back in a bit.`,+ })+ }+ activateCustomDomain(+ { projectRef },+ {+ onSuccess: () => {+ setIsActivating(false)+ },+ onError: () => {+ setIsActivating(false)+ },+ }+ )}const onCancelCustomDomain = async () => {@@ -52,6 +87,27 @@ const CustomDomainActivate = ({ projectRef, customDomain }: CustomDomainActivatecustom domain (e.g client side code or OAuth providers)</span></div>+ <div className="mt-4">+ <Alert_Shadcn_>+ <IconAlertCircle className="text-scale-1100" strokeWidth={1.5} />+ <AlertTitle_Shadcn_>+ Do remember to restore the original CNAME record from the first step before+ activating+ </AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_>+ <p className="col-span-12 text-sm lg:col-span-7 leading-6">+ Set up a CNAME record for <code className="text-xs">{customDomain.hostname}</code>+ , resolving to{' '}+ {endpoint ? (+ <code className="text-xs">{endpoint}</code>+ ) : (+ "your project's API URL"+ )}+ , with as low a TTL as possible.+ </p>+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ </div></Panel.Content><div className="w-full border-t border-scale-400" />@@ -103,22 +159,25 @@ const CustomDomainActivate = ({ projectRef, customDomain }: CustomDomainActivate</Panel.Content></div>- <ConfirmModal+ <ConfirmationModalsize="small"+ loading={isActivating}visible={isActivateConfirmModalVisible}- // @ts-ignore- title={+ header={<div>Are you sure you want to activate the custom domain{' '}<code className="text-sm">{customDomain.hostname}</code> for the project?</div>}- description="The existing Supabase subdomain will be deactivated."buttonLabel="Activate"buttonLoadingLabel="Activating"onSelectCancel={() => setIsActivateConfirmModalVisible(false)}onSelectConfirm={onActivateCustomDomain}- />+ >+ <Modal.Content className="py-3">+ <p className="text-sm">The existing Supabase subdomain will be deactivated.</p>+ </Modal.Content>+ </ConfirmationModal></>)}diff --git a/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.utils.ts b/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.utils.tsnew file mode 100644index 00000000000..ed7343de2b7--- /dev/null+++ b/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.utils.ts@@ -0,0 +1,9 @@+// [Joshen] Should tally with https://github.com/supabase/cli/blob/63790a1bd43bee06f82c4f510e709925526a4daa/internal/utils/api.go#L98+export const verifyCNAME = async (domain: string): Promise<boolean> => {+ const res = await fetch(`https://1.1.1.1/dns-query?name=${domain}&type=CNAME`, {+ method: 'GET',+ headers: { accept: 'application/dns-json' },+ })+ const verification = await res.json()+ return verification.Status === 0+}diff --git a/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx b/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsxindex 3cce8d4f062..e70a148ec55 100644--- a/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx+++ b/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx@@ -1,9 +1,18 @@import { observer } from 'mobx-react-lite'import Link from 'next/link'import { useState } from 'react'-import { Alert, Button, IconAlertCircle, IconExternalLink, IconHelpCircle, IconRefreshCw } from 'ui'+import {+ Alert,+ AlertDescription_Shadcn_,+ AlertTitle_Shadcn_,+ Alert_Shadcn_,+ Button,+ IconAlertCircle,+ IconExternalLink,+ IconHelpCircle,+ IconRefreshCw,+} from 'ui'-import InformationBox from 'components/ui/InformationBox'import Panel from 'components/ui/Panel'import { ProjectApiResponse } from 'data/config/project-api-query'import { useCustomDomainDeleteMutation } from 'data/custom-domains/custom-domains-delete-mutation'@@ -59,24 +68,20 @@ const CustomDomainVerify = ({ projectRef, customDomain, settings }: CustomDomainRecords which have been successfully verified will be removed from this list below.</p><div className="mt-4 mb-2">- <InformationBox- hideCollapse- defaultVisibility- icon={- isNotVerifiedYet ? (- <IconAlertCircle className="text-scale-1100" strokeWidth={1.5} />- ) : (- <IconHelpCircle className="text-scale-1100" strokeWidth={1.5} />- )- }- title={- isNotVerifiedYet+ <Alert_Shadcn_ variant="default">+ {isNotVerifiedYet ? (+ <IconAlertCircle className="text-scale-1100" strokeWidth={1.5} />+ ) : (+ <IconHelpCircle className="text-scale-1100" strokeWidth={1.5} />+ )}+ <AlertTitle_Shadcn_>+ {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.'- }- description={- isNotVerifiedYet ? (- <div className="space-y-1">+ : 'Please note that it may take up to 24 hours for the DNS records to propagate.'}+ </AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_>+ {isNotVerifiedYet ? (+ <div className="mt-2"><p>Do check again in a bit as it may take up to 24 hours for changes in DNSrecords to propagate.@@ -97,9 +102,9 @@ const CustomDomainVerify = ({ projectRef, customDomain, settings }: CustomDomain</Link>{' '}to check if your DNS has been propagated successfully before clicking verify.</p>- )- }- />+ )}+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_></div></div>@@ -176,8 +181,8 @@ const CustomDomainVerify = ({ projectRef, customDomain, settings }: CustomDomain<div className="!mt-4"><p className="text-sm text-scale-1000">- One of the records requires you to replace the CNAME record set up in the first step- with a TXT record.+ One of the records requires you to <span className="text-scale-1100">replace</span> the+ CNAME record set up in the first step with a TXT record.</p><p className="text-sm text-scale-1000">You'll be able to restore it back to the CNAME after the verification process has beendiff --git a/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainsConfigureHostname.tsx b/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainsConfigureHostname.tsxindex 434877e5b48..f15ec11768c 100644--- a/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainsConfigureHostname.tsx+++ b/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainsConfigureHostname.tsx@@ -1,11 +1,10 @@-import Link from 'next/link'-import * as yup from 'yup'+import { PermissionAction } from '@supabase/shared-types/out/constants'+import { useParams } from 'common'import { observer } from 'mobx-react-lite'+import Link from 'next/link'import { Button, Form, IconExternalLink, Input } from 'ui'-import { PermissionAction } from '@supabase/shared-types/out/constants'+import * as yup from 'yup'-import { useCheckPermissions, useStore } from 'hooks'-import { useParams } from 'common/hooks'import {FormActions,FormPanel,@@ -15,6 +14,8 @@ import {} from 'components/ui/Forms'import { useProjectApiQuery } from 'data/config/project-api-query'import { useCustomDomainCreateMutation } from 'data/custom-domains/custom-domains-create-mutation'+import { useCheckPermissions, useStore } from 'hooks'+import { verifyCNAME } from './CustomDomainConfig.utils'const schema = yup.object({domain: yup.string().required('A value for your custom domain is required'),@@ -30,15 +31,6 @@ const CustomDomainsConfigureHostname = () => {const endpoint = settings?.autoApiService.endpointconst canConfigureCustomDomain = useCheckPermissions(PermissionAction.UPDATE, 'projects')- const verifyCNAME = async (domain: string): Promise<boolean> => {- const res = await fetch(`https://1.1.1.1/dns-query?name=${domain}`, {- method: 'GET',- headers: { accept: 'application/dns-json' },- })- const verification = await res.json()- return verification.Status === 0- }-const onCreateCustomDomain = async (values: yup.InferType<typeof schema>) => {if (!ref) return console.error('Project ref is required')