The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update claim-dot-link-domain.ts
Steven Tey083e794df8cb
diff --git a/apps/web/lib/api/domains/claim-dot-link-domain.ts b/apps/web/lib/api/domains/claim-dot-link-domain.tsindex 686e642a50..74ced032d1 100644--- a/apps/web/lib/api/domains/claim-dot-link-domain.ts+++ b/apps/web/lib/api/domains/claim-dot-link-domain.ts@@ -8,6 +8,7 @@ import { DEFAULT_LINK_PROPS } from "@dub/utils";import { waitUntil } from "@vercel/functions";import { sendEmail } from "emails";import DomainClaimed from "emails/domain-claimed";+import { addDomainToVercel } from "./add-domain-vercel";import { deleteDomainAndLinks } from "./delete-domain-links";import { getRegisteredDotlinkDomain } from "./get-registered-dotlink-domain";@@ -30,22 +31,25 @@ export async function claimDotLinkDomain({workspace.id,);- if (registeredDotLinkDomain)+ if (registeredDotLinkDomain) {throw new DubApiError({code: "forbidden",message: "Workspace is limited to one free .link domain.",});+ }const [response, totalDomains, matchingUnverifiedDomain] = await Promise.all([+ // register the domainregisterDomain({ domain }),prisma.domain.count({where: {projectId: workspace.id,},}),- prisma.domain.findUnique({+ prisma.domain.findFirst({where: {slug: domain,+ verified: false,},include: {registeredDomain: true,@@ -53,6 +57,16 @@ export async function claimDotLinkDomain({}),]);+ // if for some reason the domain is already registered, we should fail+ if (response.RegisterResponse.Error) {+ throw new DubApiError({+ code: "forbidden",+ message: response.RegisterResponse.Error,+ });+ }++ // if the domain was added to a different workspace but is not verified+ // we should remove it to free up the domain for the current workspaceif (matchingUnverifiedDomain) {await deleteDomainAndLinks(matchingUnverifiedDomain.slug);}@@ -89,8 +103,12 @@ export async function claimDotLinkDomain({waitUntil((async () => {- // configure the DNS in the background- await configureDNS({ domain });+ await Promise.all([+ // configure the DNS with Dynadot+ configureDNS({ domain }),+ // add domain to Vercel+ addDomainToVercel(domain),+ ]);// once domain is provisioned, send emailconst workspaceWithOwner = await prisma.project.findUniqueOrThrow({