The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
[FE-2111] chore: swap custom domains reverify to query (#40777)
Alaister Youngb06d7cd98adf
diff --git a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsxindex 44d1cea30a5..56496082cbc 100644--- a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx+++ b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainVerify.tsx@@ -1,6 +1,5 @@import { AlertCircle, HelpCircle, RefreshCw } from 'lucide-react'import Link from 'next/link'-import { useState } from 'react'import { toast } from 'sonner'import { useParams } from 'common'@@ -9,9 +8,9 @@ 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 { useCustomDomainReverifyMutation } from 'data/custom-domains/custom-domains-reverify-mutation'-import { useInterval } from 'hooks/misc/useInterval'+import { useCustomDomainReverifyQuery } from 'data/custom-domains/custom-domains-reverify-query'import { DOCS_URL } from 'lib/constants'+import { useEffect } from 'react'import {AlertDescription_Shadcn_,AlertTitle_Shadcn_,@@ -24,7 +23,6 @@ import { DNSTableHeaders } from './DNSTableHeaders'const CustomDomainVerify = () => {const { ref: projectRef } = useParams()- const [isNotVerifiedYet, setIsNotVerifiedYet] = useState(false)const { data: settings } = useProjectSettingsV2Query({ projectRef })@@ -33,13 +31,6 @@ const CustomDomainVerify = () => {const isSSLCertificateDeploying =customDomain?.ssl.status !== undefined && customDomain.ssl.txt_name === undefined- const { mutate: reverifyCustomDomain, isPending: isReverifyLoading } =- useCustomDomainReverifyMutation({- onSuccess: (res) => {- if (res.status === '2_initiated') setIsNotVerifiedYet(true)- },- })-const { mutate: deleteCustomDomain, isPending: isDeleting } = useCustomDomainDeleteMutation({onSuccess: () => {toast.success(@@ -48,6 +39,28 @@ const CustomDomainVerify = () => {},})+ 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@@ -56,15 +69,9 @@ const CustomDomainVerify = () => {const onReverifyCustomDomain = () => {if (!projectRef) return console.error('Project ref is required')- reverifyCustomDomain({ projectRef })+ refetchReverify()}- useInterval(- onReverifyCustomDomain,- // Poll every 5 seconds if the SSL certificate is being deployed- isSSLCertificateDeploying && !isDeleting ? 5000 : false- )-const onCancelCustomDomain = async () => {if (!projectRef) return console.error('Project ref is required')deleteCustomDomain({ projectRef })diff --git a/apps/studio/data/custom-domains/custom-domains-reverify-mutation.ts b/apps/studio/data/custom-domains/custom-domains-reverify-mutation.tsdeleted file mode 100644index 6e0ccce0602..00000000000--- a/apps/studio/data/custom-domains/custom-domains-reverify-mutation.ts+++ /dev/null@@ -1,49 +0,0 @@-import { useMutation, useQueryClient } from '@tanstack/react-query'-import { toast } from 'sonner'--import { handleError, post } from 'data/fetchers'-import type { ResponseError, UseCustomMutationOptions } from 'types'-import { customDomainKeys } from './keys'--export type CustomDomainReverifyVariables = {- projectRef: string-}--export async function reverifyCustomDomain({ projectRef }: CustomDomainReverifyVariables) {- const { data, error } = await post(`/v1/projects/{ref}/custom-hostname/reverify`, {- params: { path: { ref: projectRef } },- })-- if (error) handleError(error)- return data-}--type CustomDomainReverifyData = Awaited<ReturnType<typeof reverifyCustomDomain>>--export const useCustomDomainReverifyMutation = ({- onSuccess,- onError,- ...options-}: Omit<- UseCustomMutationOptions<CustomDomainReverifyData, ResponseError, CustomDomainReverifyVariables>,- 'mutationFn'-> = {}) => {- const queryClient = useQueryClient()-- return useMutation<CustomDomainReverifyData, ResponseError, CustomDomainReverifyVariables>({- mutationFn: (vars) => reverifyCustomDomain(vars),- async onSuccess(data, variables, context) {- const { projectRef } = variables- await queryClient.invalidateQueries({ queryKey: customDomainKeys.list(projectRef) })- await onSuccess?.(data, variables, context)- },- async onError(data, variables, context) {- if (onError === undefined) {- toast.error(`Failed to reverify custom domain: ${data.message}`)- } else {- onError(data, variables, context)- }- },- ...options,- })-}diff --git a/apps/studio/data/custom-domains/custom-domains-reverify-query.ts b/apps/studio/data/custom-domains/custom-domains-reverify-query.tsnew file mode 100644index 00000000000..e9ef3b027f6--- /dev/null+++ b/apps/studio/data/custom-domains/custom-domains-reverify-query.ts@@ -0,0 +1,48 @@+import { useQuery, useQueryClient } from '@tanstack/react-query'++import { handleError, post } from 'data/fetchers'+import { useEffect } from 'react'+import type { ResponseError, UseCustomQueryOptions } from 'types'+import { customDomainKeys } from './keys'++export type CustomDomainReverifyVariables = {+ projectRef?: string+}++export async function reverifyCustomDomain({ projectRef }: CustomDomainReverifyVariables) {+ if (!projectRef) throw new Error('projectRef is required')++ const { data, error } = await post(`/v1/projects/{ref}/custom-hostname/reverify`, {+ params: { path: { ref: projectRef } },+ })++ if (error) handleError(error)+ return data+}++export type CustomDomainReverifyData = Awaited<ReturnType<typeof reverifyCustomDomain>>+export type CustomDomainReverifyError = ResponseError++export const useCustomDomainReverifyQuery = (+ { projectRef }: CustomDomainReverifyVariables,+ {+ enabled = true,+ ...options+ }: UseCustomQueryOptions<CustomDomainReverifyData, CustomDomainReverifyError> = {}+) => {+ const client = useQueryClient()++ const query = useQuery<CustomDomainReverifyData, CustomDomainReverifyError>({+ queryKey: customDomainKeys.reverify(projectRef),+ queryFn: () => reverifyCustomDomain({ projectRef }),+ enabled: enabled && typeof projectRef !== 'undefined',+ ...options,+ })++ useEffect(() => {+ if (!query.isSuccess) return+ client.invalidateQueries({ queryKey: customDomainKeys.list(projectRef) })+ }, [query.isSuccess, projectRef, client])++ return query+}diff --git a/apps/studio/data/custom-domains/keys.ts b/apps/studio/data/custom-domains/keys.tsindex e63bfeb67ca..b5440a62b6c 100644--- a/apps/studio/data/custom-domains/keys.ts+++ b/apps/studio/data/custom-domains/keys.ts@@ -1,3 +1,5 @@export const customDomainKeys = {list: (projectRef: string | undefined) => ['projects', projectRef, 'custom-domains'] as const,+ reverify: (projectRef: string | undefined) =>+ ['projects', projectRef, 'custom-domains', 'reverify'] as const,}