Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

add domain claimed email

Steven Tey0458e47dcde6
diff --git a/apps/web/app/api/domains/register/route.ts b/apps/web/app/api/domains/register/route.ts
index 658ab74c2f..699cdebed8 100644
--- a/apps/web/app/api/domains/register/route.ts
+++ b/apps/web/app/api/domains/register/route.ts
@@ -9,7 +9,7 @@ const schema = z.object({
.min(1)
.endsWith(".link")
.transform((domain) => domain.toLowerCase())
- .describe("We only support .link domains for now."),
+ .describe("The domain to claim. We only support .link domains for now."),
});
// POST /api/domains/register - register a domain
diff --git a/apps/web/emails/domain-claimed.tsx b/apps/web/emails/domain-claimed.tsx
new file mode 100644
index 0000000000..6c75f09cda
--- /dev/null
+++ b/apps/web/emails/domain-claimed.tsx
@@ -0,0 +1,79 @@
+import { DUB_WORDMARK } from "@dub/utils";
+import {
+ Body,
+ Container,
+ Head,
+ Heading,
+ Html,
+ Img,
+ Link,
+ Preview,
+ Section,
+ Tailwind,
+ Text,
+} from "@react-email/components";
+import Footer from "./components/footer";
+
+export default function DomainClaimed({
+ email = "[email protected]",
+ domain = "dub.link",
+ workspaceSlug = "dub",
+}: {
+ email: string;
+ domain: string;
+ workspaceSlug: string;
+}) {
+ return (
+ <Html>
+ <Head />
+ <Preview>Successfully claimed your .link domain!</Preview>
+ <Tailwind>
+ <Body className="mx-auto my-auto bg-white font-sans">
+ <Container className="mx-auto my-10 max-w-[500px] rounded border border-solid border-gray-200 px-10 py-5">
+ <Section className="mt-8">
+ <Img
+ src={DUB_WORDMARK}
+ height="40"
+ alt="Dub"
+ className="mx-auto my-0"
+ />
+ </Section>
+ <Heading className="mx-0 my-7 p-0 text-center text-xl font-semibold text-black">
+ Successfully claimed your .link domain!
+ </Heading>
+ <Text className="text-sm leading-6 text-black">
+ Congratulations! You have successfully claimed your free{" "}
+ <code className="text-purple-600">{domain}</code> domain for your
+ Dub workspace{" "}
+ <Link
+ href={`https://app.dub.co/${workspaceSlug}`}
+ className="font-medium text-blue-600 no-underline"
+ >
+ {workspaceSlug}↗
+ </Link>
+ .
+ </Text>
+ <Section className="my-8 text-center">
+ <Link
+ className="rounded-full bg-black px-6 py-3 text-center text-[12px] font-semibold text-white no-underline"
+ href={`https://app.dub.co/${workspaceSlug}/settings/domains`}
+ >
+ Manage your domain
+ </Link>
+ </Section>
+ <Text className="text-sm leading-6 text-black">
+ Once the domain is fully provisioned, you can start creating links
+ with it. This process can take anywhere between a few minutes to
+ an hour.
+ </Text>
+ <Text className="text-sm leading-6 text-black">
+ If your domain is not active after 1 hour, please reply to this
+ email and we will look into it.
+ </Text>
+ <Footer email={email} />
+ </Container>
+ </Body>
+ </Tailwind>
+ </Html>
+ );
+}
diff --git a/apps/web/lib/api/domains/claim-dot-link-domain.ts b/apps/web/lib/api/domains/claim-dot-link-domain.ts
index bb8a94d62f..686e642a50 100644
--- a/apps/web/lib/api/domains/claim-dot-link-domain.ts
+++ b/apps/web/lib/api/domains/claim-dot-link-domain.ts
@@ -6,6 +6,9 @@ import { prisma } from "@/lib/prisma";
import { WorkspaceWithUsers } from "@/lib/types";
import { DEFAULT_LINK_PROPS } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
+import { sendEmail } from "emails";
+import DomainClaimed from "emails/domain-claimed";
+import { deleteDomainAndLinks } from "./delete-domain-links";
import { getRegisteredDotlinkDomain } from "./get-registered-dotlink-domain";
export async function claimDotLinkDomain({
@@ -33,38 +36,39 @@ export async function claimDotLinkDomain({
message: "Workspace is limited to one free .link domain.",
});
- const response = await registerDomain({ domain });
- const slug = response.RegisterResponse.DomainName;
-
- const totalDomains = await prisma.domain.count({
- where: {
- projectId: workspace.id,
- },
- });
-
- // Delete any matching unverified domain
- await prisma.domain.deleteMany({
- where: {
- slug,
- verified: false,
- registeredDomain: {
- is: null,
+ const [response, totalDomains, matchingUnverifiedDomain] = await Promise.all([
+ registerDomain({ domain }),
+ prisma.domain.count({
+ where: {
+ projectId: workspace.id,
},
- },
- });
+ }),
+ prisma.domain.findUnique({
+ where: {
+ slug: domain,
+ },
+ include: {
+ registeredDomain: true,
+ },
+ }),
+ ]);
+
+ if (matchingUnverifiedDomain) {
+ await deleteDomainAndLinks(matchingUnverifiedDomain.slug);
+ }
await Promise.all([
// Create the workspace domain
prisma.domain.create({
data: {
projectId: workspace.id,
- slug,
+ slug: domain,
verified: true,
lastChecked: new Date(),
primary: totalDomains === 0,
registeredDomain: {
create: {
- slug,
+ slug: domain,
expiresAt: new Date(response.RegisterResponse.Expiration || ""),
projectId: workspace.id,
},
@@ -74,7 +78,7 @@ export async function claimDotLinkDomain({
// Create the root link
createLink({
...DEFAULT_LINK_PROPS,
- domain: slug,
+ domain,
key: "_root",
url: "",
tags: undefined,
@@ -83,8 +87,43 @@ export async function claimDotLinkDomain({
}),
]);
- // Configure the DNS in the background
- waitUntil(configureDNS({ domain: slug }));
+ waitUntil(
+ (async () => {
+ // configure the DNS in the background
+ await configureDNS({ domain });
+
+ // once domain is provisioned, send email
+ const workspaceWithOwner = await prisma.project.findUniqueOrThrow({
+ where: {
+ id: workspace.id,
+ },
+ include: {
+ users: {
+ where: {
+ role: "owner",
+ },
+ select: {
+ user: true,
+ },
+ },
+ },
+ });
+
+ workspaceWithOwner.users.map(({ user }) => {
+ if (user.email) {
+ sendEmail({
+ email: user.email,
+ subject: "Successfully claimed your .link domain!",
+ react: DomainClaimed({
+ email: user.email,
+ domain,
+ workspaceSlug: workspace.slug,
+ }),
+ });
+ }
+ });
+ })(),
+ );
return response;
}