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.

Support registering premium domains (#4088)

Steven Teyd9a711251016
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/refresh-domain.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/domains/components/refresh-domain.tsx
similarity index 96%
rename from apps/web/app/(ee)/admin.dub.co/(dashboard)/components/refresh-domain.tsx
rename to apps/web/app/(ee)/admin.dub.co/(dashboard)/domains/components/refresh-domain.tsx
index 3586210ed2..88b9732c2b 100644
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/refresh-domain.tsx
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/domains/components/refresh-domain.tsx
@@ -10,7 +10,7 @@ export function RefreshDomain() {
<div className="flex flex-col space-y-5">
<form
action={async (data) =>
- await fetch("/api/admin/refresh-domain", {
+ await fetch("/api/admin/domains/refresh", {
method: "POST",
body: JSON.stringify({
domain: data.get("domain"),
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/domains/components/register-premium-domain.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/domains/components/register-premium-domain.tsx
new file mode 100644
index 0000000000..58e44200ef
--- /dev/null
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/domains/components/register-premium-domain.tsx
@@ -0,0 +1,314 @@
+"use client";
+
+import { normalizeDomainInput } from "@/lib/api/domains/normalize-domain-input";
+import { Button, LoadingSpinner } from "@dub/ui";
+import { cn, currencyFormatter } from "@dub/utils";
+import { useEffect, useState } from "react";
+import { useFormStatus } from "react-dom";
+import { toast } from "sonner";
+import { useDebounce } from "use-debounce";
+
+interface DomainSearchResult {
+ domain: string;
+ available: boolean;
+ price: string | null;
+ premium: boolean;
+ prices: {
+ registration: number | null;
+ renewal: number | null;
+ } | null;
+}
+
+function toLinkDomain(input: string) {
+ const normalized = normalizeDomainInput(input);
+ if (!normalized) return "";
+ return normalized.endsWith(".link") ? normalized : `${normalized}.link`;
+}
+
+export function RegisterPremiumDomain() {
+ const [domain, setDomain] = useState("");
+ const [workspaceSlug, setWorkspaceSlug] = useState("");
+ const [debouncedDomain] = useDebounce(domain, 500);
+ const [isSearching, setIsSearching] = useState(false);
+ const [searchResult, setSearchResult] = useState<DomainSearchResult | null>(
+ null,
+ );
+
+ useEffect(() => {
+ const linkDomain = toLinkDomain(debouncedDomain);
+
+ if (!linkDomain) {
+ setSearchResult(null);
+ return;
+ }
+
+ const search = async () => {
+ setIsSearching(true);
+
+ const response = await fetch(
+ `/api/admin/domains/search-availability?domain=${encodeURIComponent(linkDomain)}`,
+ );
+
+ setIsSearching(false);
+
+ if (!response.ok) {
+ const payload = await response.json().catch(() => ({}));
+ toast.error(
+ typeof payload.error === "string"
+ ? payload.error
+ : "Failed to search domain availability.",
+ );
+ setSearchResult(null);
+ return;
+ }
+
+ const data = (await response.json()) as DomainSearchResult[];
+ setSearchResult(
+ data.find((result) => result.domain === linkDomain) ?? data[0] ?? null,
+ );
+ };
+
+ search();
+ }, [debouncedDomain]);
+
+ return (
+ <div className="flex flex-col space-y-5">
+ <form
+ action={async (data) => {
+ try {
+ const domainInput = data.get("domain")?.toString().trim();
+ const workspaceSlug = data.get("workspaceSlug")?.toString().trim();
+ const linkDomain = domainInput ? toLinkDomain(domainInput) : "";
+
+ if (!linkDomain) {
+ toast.error("Please enter a domain.");
+ return;
+ }
+
+ if (!workspaceSlug) {
+ toast.error("Please enter a workspace slug.");
+ return;
+ }
+
+ if (!searchResult?.premium || !searchResult.available) {
+ toast.error("Domain must be an available premium .link domain.");
+ return;
+ }
+
+ const priceLabel = searchResult.prices?.registration
+ ? currencyFormatter(searchResult.prices.registration, {
+ trailingZeroDisplay: "stripIfInteger",
+ })
+ : "the listed price";
+
+ const confirmed = window.confirm(
+ `Register premium domain "${linkDomain}" for workspace "${workspaceSlug}"? The workspace will be charged ${priceLabel}.`,
+ );
+ if (!confirmed) return;
+
+ const res = await fetch("/api/admin/domains/register-premium", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ domain: linkDomain,
+ workspaceSlug,
+ }),
+ });
+
+ const text = await res.text();
+ let payload: Record<string, unknown> = {};
+ try {
+ payload = text
+ ? (JSON.parse(text) as Record<string, unknown>)
+ : {};
+ } catch {
+ payload = {};
+ }
+
+ if (!res.ok) {
+ toast.error(
+ typeof payload.error === "string"
+ ? payload.error
+ : text.trim().slice(0, 200) || "Request failed",
+ );
+ return;
+ }
+
+ const message =
+ typeof payload.message === "string"
+ ? payload.message
+ : "Registration initiated";
+ const invoiceId =
+ typeof payload.invoiceId === "string"
+ ? payload.invoiceId
+ : undefined;
+ const paymentIntentStatus =
+ typeof payload.paymentIntentStatus === "string"
+ ? payload.paymentIntentStatus
+ : undefined;
+
+ toast.success(message, {
+ description: invoiceId
+ ? `Invoice: ${invoiceId}${
+ paymentIntentStatus
+ ? ` · Payment status: ${paymentIntentStatus}`
+ : ""
+ }`
+ : undefined,
+ });
+ } catch {
+ toast.error(
+ "Could not reach the server or complete registration. Check your connection and try again.",
+ );
+ }
+ }}
+ >
+ <Form
+ domain={domain}
+ setDomain={setDomain}
+ workspaceSlug={workspaceSlug}
+ setWorkspaceSlug={setWorkspaceSlug}
+ isSearching={isSearching}
+ searchResult={searchResult}
+ />
+ </form>
+ </div>
+ );
+}
+
+const Form = ({
+ domain,
+ setDomain,
+ workspaceSlug,
+ setWorkspaceSlug,
+ isSearching,
+ searchResult,
+}: {
+ domain: string;
+ setDomain: (domain: string) => void;
+ workspaceSlug: string;
+ setWorkspaceSlug: (workspaceSlug: string) => void;
+ isSearching: boolean;
+ searchResult: DomainSearchResult | null;
+}) => {
+ const { pending } = useFormStatus();
+ const linkDomain = toLinkDomain(domain);
+
+ return (
+ <div className="flex flex-col gap-3">
+ <div>
+ <div className="relative flex w-full rounded-md shadow-sm">
+ <input
+ name="domain"
+ id="register-premium-domain"
+ type="text"
+ required
+ disabled={pending}
+ autoComplete="off"
+ value={domain}
+ onChange={(e) => setDomain(e.target.value)}
+ className={cn(
+ "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
+ pending && "bg-neutral-100",
+ )}
+ placeholder="domain.link"
+ />
+ {isSearching && (
+ <LoadingSpinner className="absolute inset-y-0 right-2 my-auto h-full w-5 text-neutral-400" />
+ )}
+ </div>
+ {(isSearching || searchResult) && (
+ <p className="mt-2 text-sm text-neutral-600">
+ {isSearching ? (
+ <>Checking availability for {linkDomain}...</>
+ ) : searchResult ? (
+ <>
+ <span className="font-medium text-neutral-800">
+ {searchResult.domain}
+ </span>{" "}
+ is{" "}
+ {searchResult.available ? (
+ <>
+ available{" "}
+ {searchResult.premium ? "as a premium domain " : ""}for{" "}
+ {typeof searchResult.prices?.registration === "number" ? (
+ <span className="font-medium text-neutral-800">
+ {currencyFormatter(searchResult.prices.registration, {
+ trailingZeroDisplay: "stripIfInteger",
+ })}
+ </span>
+ ) : (
+ "—"
+ )}
+ {typeof searchResult.prices?.renewal === "number" ? (
+ <>
+ {" "}
+ (renews at{" "}
+ <span className="font-medium text-neutral-800">
+ {currencyFormatter(searchResult.prices.renewal, {
+ trailingZeroDisplay: "stripIfInteger",
+ })}
+ /year
+ </span>
+ )
+ </>
+ ) : (
+ "—"
+ )}
+ </>
+ ) : (
+ "not available"
+ )}
+ .
+ </>
+ ) : null}
+ </p>
+ )}
+ </div>
+ <div className="relative flex w-full rounded-md shadow-sm">
+ <input
+ name="workspaceSlug"
+ id="register-premium-workspace"
+ type="text"
+ required
+ disabled={pending}
+ autoComplete="off"
+ value={workspaceSlug}
+ onChange={(e) => setWorkspaceSlug(e.target.value)}
+ className={cn(
+ "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
+ pending && "bg-neutral-100",
+ )}
+ placeholder="workspace-slug"
+ />
+ </div>
+ <Button
+ type="submit"
+ variant="primary"
+ className="h-9 w-full"
+ loading={pending}
+ disabled={
+ isSearching ||
+ !domain.trim() ||
+ !workspaceSlug.trim() ||
+ !searchResult?.premium ||
+ !searchResult?.available
+ }
+ text={
+ searchResult?.premium &&
+ searchResult.available &&
+ searchResult.prices?.registration
+ ? `Register for ${currencyFormatter(
+ searchResult.prices.registration,
+ {
+ trailingZeroDisplay: "stripIfInteger",
+ },
+ )}`
+ : "Register domain"
+ }
+ />
+ </div>
+ );
+};
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/renew-domain.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/domains/components/renew-domain.tsx
similarity index 64%
rename from apps/web/app/(ee)/admin.dub.co/(dashboard)/components/renew-domain.tsx
rename to apps/web/app/(ee)/admin.dub.co/(dashboard)/domains/components/renew-domain.tsx
index 0b7bf1deec..408adeb312 100644
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/renew-domain.tsx
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/domains/components/renew-domain.tsx
@@ -1,11 +1,14 @@
"use client";
-import { LoadingSpinner } from "@dub/ui";
+import { Button, LoadingSpinner } from "@dub/ui";
import { cn } from "@dub/utils";
+import { useState } from "react";
import { useFormStatus } from "react-dom";
import { toast } from "sonner";
export function RenewDomain() {
+ const [domain, setDomain] = useState("");
+
return (
<div className="flex flex-col space-y-5">
<form
@@ -23,7 +26,7 @@ export function RenewDomain() {
);
if (!confirmed) return;
- const res = await fetch("/api/admin/renew-domain", {
+ const res = await fetch("/api/admin/domains/renew", {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -81,34 +84,52 @@ export function RenewDomain() {
}
}}
>
- <Form />
+ <Form domain={domain} setDomain={setDomain} />
</form>
</div>
);
}
-const Form = () => {
+const Form = ({
+ domain,
+ setDomain,
+}: {
+ domain: string;
+ setDomain: (domain: string) => void;
+}) => {
const { pending } = useFormStatus();
return (
- <div className="relative flex w-full rounded-md shadow-sm">
- <input
- name="domain"
- id="renew-domain"
- type="text"
- required
- disabled={pending}
- autoComplete="off"
- className={cn(
- "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
- pending && "bg-neutral-100",
+ <div className="flex flex-col gap-3">
+ <div className="relative flex w-full rounded-md shadow-sm">
+ <input
+ name="domain"
+ id="renew-domain"
+ type="text"
+ required
+ disabled={pending}
+ autoComplete="off"
+ value={domain}
+ onChange={(e) => setDomain(e.target.value)}
+ className={cn(
+ "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
+ pending && "bg-neutral-100",
+ )}
+ placeholder="acme.link"
+ aria-invalid="true"
+ />
+ {pending && (
+ <LoadingSpinner className="absolute inset-y-0 right-2 my-auto h-full w-5 text-neutral-400" />
)}
- placeholder="acme.link"
- aria-invalid="true"
+ </div>
+ <Button
+ type="submit"
+ variant="primary"
+ className="h-9 w-full"
+ loading={pending}
+ disabled={pending || !domain.trim()}
+ text="Renew domain"
/>
- {pending && (
- <LoadingSpinner className="absolute inset-y-0 right-2 my-auto h-full w-5 text-neutral-400" />
- )}
</div>
);
};
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/domains/page.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/domains/page.tsx
new file mode 100644
index 0000000000..c01df8f711
--- /dev/null
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/domains/page.tsx
@@ -0,0 +1,36 @@
+import { RefreshDomain } from "./components/refresh-domain";
+import { RegisterPremiumDomain } from "./components/register-premium-domain";
+import { RenewDomain } from "./components/renew-domain";
+
+export default function AdminDomainsPage() {
+ return (
+ <div className="mx-auto flex w-full max-w-screen-sm flex-col divide-y divide-neutral-200 overflow-auto bg-white">
+ <div className="flex flex-col space-y-4 px-5 py-10">
+ <h2 className="text-xl font-semibold">Register premium .link domain</h2>
+ <p className="text-sm text-neutral-500">
+ Create a domain-renewal invoice and charge the workspace default
+ payment method for a premium .link domain. On success, Stripe
+ webhooks register the domain on Dynadot and provision it in Dub.
+ </p>
+ <RegisterPremiumDomain />
+ </div>
+ <div className="flex flex-col space-y-4 px-5 py-10">
+ <h2 className="text-xl font-semibold">Renew domain (.link)</h2>
+ <p className="text-sm text-neutral-500">
+ Create a new domain-renewal invoice and charge the workspace default
+ payment method. On success, Stripe webhooks extend Dub expiry and
+ re-enable Dynadot auto-renew. If the domain has already expired at
+ Dynadot, you may still need to renew it in the Dynadot dashboard.
+ </p>
+ <RenewDomain />
+ </div>
+ <div className="flex flex-col space-y-4 px-5 py-10">
+ <h2 className="text-xl font-semibold">Refresh domain</h2>
+ <p className="text-sm text-neutral-500">
+ Remove and re-add domain from Vercel
+ </p>
+ <RefreshDomain />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/layout-nav-client.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/layout-nav-client.tsx
index 7d67dfc2d3..50416c3f16 100644
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/layout-nav-client.tsx
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/layout-nav-client.tsx
@@ -40,6 +40,10 @@ const tabs = [
href: "/revenue",
label: "Revenue",
},
+ {
+ href: "/domains",
+ label: "Domains",
+ },
];
export function AdminNav() {
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx
index 338d9beae3..6c53f3083d 100644
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx
@@ -2,8 +2,6 @@ import { BanLink } from "./components/ban-link";
import { DeletePartnerAccount } from "./components/delete-partner-account";
import { ImpersonateUser } from "./components/impersonate-user";
import { ImpersonateWorkspace } from "./components/impersonate-workspace";
-import { RefreshDomain } from "./components/refresh-domain";
-import { RenewDomain } from "./components/renew-domain";
import { ResetLoginAttempts } from "./components/reset-login-attempts";
import { SlackSupportInvite } from "./components/slack-support-invite";
@@ -43,23 +41,6 @@ export default function AdminPage() {
</p>
<DeletePartnerAccount />
</div>
- <div className="flex flex-col space-y-4 px-5 py-10">
- <h2 className="text-xl font-semibold">Renew domain (.link)</h2>
- <p className="text-sm text-neutral-500">
- Create a new domain-renewal invoice and charge the workspace default
- payment method. On success, Stripe webhooks extend Dub expiry and
- re-enable Dynadot auto-renew. If the domain has already expired at
- Dynadot, you may still need to renew it in the Dynadot dashboard.
- </p>
- <RenewDomain />
- </div>
- <div className="flex flex-col space-y-4 px-5 py-10">
- <h2 className="text-xl font-semibold">Refresh Domain</h2>
- <p className="text-sm text-neutral-500">
- Remove and re-add domain from Vercel
- </p>
- <RefreshDomain />
- </div>
<div className="flex flex-col space-y-4 px-5 py-10">
<h2 className="text-xl font-semibold">Reset Login Attempts</h2>
<p className="text-sm text-neutral-500">
diff --git a/apps/web/app/(ee)/api/admin/refresh-domain/route.ts b/apps/web/app/(ee)/api/admin/domains/refresh/route.ts
similarity index 95%
rename from apps/web/app/(ee)/api/admin/refresh-domain/route.ts
rename to apps/web/app/(ee)/api/admin/domains/refresh/route.ts
index 5a207c738c..80098d212b 100644
--- a/apps/web/app/(ee)/api/admin/refresh-domain/route.ts
+++ b/apps/web/app/(ee)/api/admin/domains/refresh/route.ts
@@ -2,7 +2,7 @@ import { addDomainToVercel } from "@/lib/api/domains/add-domain-vercel";
import { withAdmin } from "@/lib/auth";
import { NextResponse } from "next/server";
-// POST /api/admin/refresh-domain
+// POST /api/admin/domains/refresh
export const POST = withAdmin(async ({ req }) => {
const { domain } = await req.json();
diff --git a/apps/web/app/(ee)/api/admin/domains/register-premium/route.ts b/apps/web/app/(ee)/api/admin/domains/register-premium/route.ts
new file mode 100644
index 0000000000..728c8bcee2
--- /dev/null
+++ b/apps/web/app/(ee)/api/admin/domains/register-premium/route.ts
@@ -0,0 +1,92 @@
+import { initiatePremiumDomainRegistration } from "@/lib/api/domains/initiate-premium-domain-registration";
+import { normalizeDomainInput } from "@/lib/api/domains/normalize-domain-input";
+import { DubApiError } from "@/lib/api/errors";
+import { withAdmin } from "@/lib/auth";
+import { prisma } from "@/lib/prisma";
+import { currencyFormatter } from "@dub/utils";
+import { NextResponse } from "next/server";
+import * as z from "zod/v4";
+
+const schema = z.object({
+ domain: z.string().min(1).transform(normalizeDomainInput),
+ workspaceSlug: z.string().min(1).trim().toLowerCase(),
+});
+
+// POST /api/admin/domains/register-premium
+export const POST = withAdmin(async ({ req }) => {
+ const parsed = schema.safeParse(await req.json());
+ if (!parsed.success) {
+ return NextResponse.json({ error: parsed.error.message }, { status: 400 });
+ }
+
+ const { domain, workspaceSlug } = parsed.data;
+
+ if (!domain) {
+ return NextResponse.json({ error: "Invalid domain." }, { status: 400 });
+ }
+
+ if (!domain.endsWith(".link")) {
+ return NextResponse.json(
+ { error: "Only .link domains are supported." },
+ { status: 400 },
+ );
+ }
+
+ const workspace = await prisma.project.findUnique({
+ where: { slug: workspaceSlug },
+ select: {
+ id: true,
+ slug: true,
+ plan: true,
+ stripeId: true,
+ trialEndsAt: true,
+ invoicePrefix: true,
+ },
+ });
+
+ if (!workspace) {
+ return NextResponse.json(
+ { error: `Workspace "${parsed.data.workspaceSlug}" not found.` },
+ { status: 404 },
+ );
+ }
+
+ try {
+ const response = await initiatePremiumDomainRegistration({
+ domain,
+ workspace,
+ skipWorkspaceChecks: true,
+ });
+
+ const status = response.paymentIntentStatus;
+
+ if (status === "succeeded") {
+ return NextResponse.json({
+ success: true,
+ message: `Charge succeeded (${currencyFormatter(response.registrationPriceCents)}). Domain registration will finalize via Stripe webhook.`,
+ ...response,
+ });
+ }
+
+ return NextResponse.json({
+ success: true,
+ message: `Payment initiated (${currencyFormatter(response.registrationPriceCents)}). Domain registration will finalize via Stripe webhook once payment succeeds.`,
+ ...response,
+ });
+ } catch (error) {
+ if (error instanceof DubApiError) {
+ const status =
+ error.code === "conflict"
+ ? 409
+ : error.code === "unprocessable_entity"
+ ? 422
+ : error.code === "forbidden"
+ ? 403
+ : 400;
+
+ return NextResponse.json({ error: error.message }, { status });
+ }
+
+ throw error;
+ }
+});
diff --git a/apps/web/app/(ee)/api/admin/renew-domain/route.ts b/apps/web/app/(ee)/api/admin/domains/renew/route.ts
similarity index 83%
rename from apps/web/app/(ee)/api/admin/renew-domain/route.ts
rename to apps/web/app/(ee)/api/admin/domains/renew/route.ts
index 35c09df863..07364c97da 100644
--- a/apps/web/app/(ee)/api/admin/renew-domain/route.ts
+++ b/apps/web/app/(ee)/api/admin/domains/renew/route.ts
@@ -1,4 +1,5 @@
import { createId } from "@/lib/api/create-id";
+import { normalizeDomainInput } from "@/lib/api/domains/normalize-domain-input";
import { withAdmin } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { createPaymentIntent } from "@/lib/stripe/create-payment-intent";
@@ -6,23 +7,23 @@ import { NextResponse } from "next/server";
import * as z from "zod/v4";
const schema = z.object({
- domain: z.string().min(1),
+ domain: z.string().min(1).transform(normalizeDomainInput),
});
-// POST /api/admin/renew-domain
+// POST /api/admin/domains/renew
export const POST = withAdmin(async ({ req }) => {
const parsed = schema.safeParse(await req.json());
if (!parsed.success) {
return NextResponse.json({ error: parsed.error.message }, { status: 400 });
}
- const normalized = normalizeDomainInput(parsed.data.domain);
- if (!normalized) {
+ const { domain } = parsed.data;
+ if (!domain) {
return NextResponse.json({ error: "Invalid domain." }, { status: 400 });
}
const registered = await prisma.registeredDomain.findFirst({
- where: { slug: normalized },
+ where: { slug: domain },
select: {
slug: true,
renewalFee: true,
@@ -39,7 +40,7 @@ export const POST = withAdmin(async ({ req }) => {
if (!registered) {
return NextResponse.json(
- { error: `No registered domain found for "${normalized}".` },
+ { error: `No registered domain found for "${domain}".` },
{ status: 404 },
);
}
@@ -53,7 +54,7 @@ export const POST = withAdmin(async ({ req }) => {
if (!registered.renewalFee || registered.renewalFee <= 0) {
return NextResponse.json(
- { error: `Domain "${normalized}" has no valid renewal fee configured.` },
+ { error: `Domain "${domain}" has no valid renewal fee configured.` },
{ status: 400 },
);
}
@@ -74,7 +75,7 @@ export const POST = withAdmin(async ({ req }) => {
const slugs = inv.registeredDomains as string[] | null;
return (
Array.isArray(slugs) &&
- (slugs.includes(registered.slug) || slugs.includes(normalized))
+ (slugs.includes(registered.slug) || slugs.includes(domain))
);
});
@@ -165,25 +166,3 @@ export const POST = withAdmin(async ({ req }) => {
paymentIntentStatus: status,
});
});
-
-function normalizeDomainInput(raw: string): string {
- let s = raw.trim().toLowerCase();
- if (!s) {
- return s;
- }
- try {
- if (s.includes("://")) {
- const url = new URL(s);
- s = url.hostname;
- } else if (s.includes("/")) {
- const url = new URL(`https://${s}`);
- s = url.hostname;
- }
- } catch {
- // keep s as typed
- }
- if (s.startsWith("www.")) {
- s = s.slice(4);
- }
- return s;
-}
diff --git a/apps/web/app/(ee)/api/admin/domains/search-availability/route.ts b/apps/web/app/(ee)/api/admin/domains/search-availability/route.ts
new file mode 100644
index 0000000000..0a6a628d39
--- /dev/null
+++ b/apps/web/app/(ee)/api/admin/domains/search-availability/route.ts
@@ -0,0 +1,34 @@
+import { getDomainSearchAvailability } from "@/lib/api/domains/get-domain-search-availability";
+import { normalizeDomainInput } from "@/lib/api/domains/normalize-domain-input";
+import { withAdmin } from "@/lib/auth";
+import { NextResponse } from "next/server";
+import * as z from "zod/v4";
+
+const schema = z.object({
+ domain: z
+ .string()
+ .min(1)
+ .transform((domain) => {
+ const normalized = normalizeDomainInput(domain);
+ return normalized.endsWith(".link") ? normalized : `${normalized}.link`;
+ }),
+});
+
+// GET /api/admin/domains/search-availability - search a .link domain (admin only)
+export const GET = withAdmin(async ({ searchParams }) => {
+ const parsed = schema.safeParse(searchParams);
+
+ if (!parsed.success) {
+ return NextResponse.json({ error: parsed.error.message }, { status: 400 });
+ }
+
+ const { domain } = parsed.data;
+
+ if (!domain) {
+ return NextResponse.json({ error: "Invalid domain." }, { status: 400 });
+ }
+
+ const response = await getDomainSearchAvailability(domain);
+
+ return NextResponse.json(response);
+});
diff --git a/apps/web/app/(ee)/api/domains/status/route.ts b/apps/web/app/(ee)/api/domains/status/route.ts
index 39e5b22924..0844e5e6cc 100644
--- a/apps/web/app/(ee)/api/domains/status/route.ts
+++ b/apps/web/app/(ee)/api/domains/status/route.ts
@@ -51,8 +51,9 @@ export const GET = withWorkspace(
domainsOnDub.map(({ slug: domain }) => ({
domain,
available: false,
- price: null,
premium: null,
+ prices: null,
+ price: null,
})),
);
}
diff --git a/apps/web/app/(ee)/api/stripe/webhook/charge-succeeded.ts b/apps/web/app/(ee)/api/stripe/webhook/charge-succeeded.ts
index 55e52aa8e5..771bf8d20e 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/charge-succeeded.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/charge-succeeded.ts
@@ -1,3 +1,8 @@
+import { finalizePremiumDomainRegistration } from "@/lib/api/domains/finalize-premium-domain-registration";
+import {
+ isDomainRegistrationInvoice,
+ parseRegisteredDomainSlugs,
+} from "@/lib/api/domains/is-domain-registration-invoice";
import { qstash } from "@/lib/cron";
import { setRenewOption } from "@/lib/dynadot/set-renew-option";
import { prisma } from "@/lib/prisma";
@@ -105,10 +110,24 @@ async function processPayoutInvoice({ invoice }: { invoice: Invoice }) {
}
async function processDomainRenewalInvoice({ invoice }: { invoice: Invoice }) {
+ const slugs = parseRegisteredDomainSlugs(invoice.registeredDomains);
+
+ if (
+ await isDomainRegistrationInvoice({
+ slugs,
+ workspaceId: invoice.workspaceId,
+ })
+ ) {
+ return await finalizePremiumDomainRegistration({
+ domain: slugs[0],
+ workspaceId: invoice.workspaceId,
+ });
+ }
+
const domains = await prisma.registeredDomain.findMany({
where: {
slug: {
- in: invoice.registeredDomains as string[],
+ in: slugs,
},
},
orderBy: {
diff --git a/apps/web/app/api/domains/search-availability/route.ts b/apps/web/app/api/domains/search-availability/route.ts
index 281351011a..4bd0a6c376 100644
--- a/apps/web/app/api/domains/search-availability/route.ts
+++ b/apps/web/app/api/domains/search-availability/route.ts
@@ -1,6 +1,5 @@
+import { getDomainSearchAvailability } from "@/lib/api/domains/get-domain-search-availability";
import { withWorkspace } from "@/lib/auth";
-import { searchDomainsAvailability } from "@/lib/dynadot/search-domains";
-import { prisma } from "@/lib/prisma";
import { ratelimit } from "@/lib/upstash";
import { NextResponse } from "next/server";
import * as z from "zod/v4";
@@ -28,33 +27,7 @@ export const GET = withWorkspace(
return new Response("Don't DDoS me pls 🥺", { status: 429 });
}
- // check if the domain is already registered on Dub
- const domainOnDub = await prisma.domain.findUnique({
- where: {
- slug: domain,
- verified: true,
- },
- });
-
- if (domainOnDub) {
- return NextResponse.json([
- {
- domain: domainOnDub.slug,
- available: false,
- price: null,
- },
- ]);
- }
-
- // search for the domain on Dynadot
- const response = await searchDomainsAvailability({
- domains: {
- domain0: domain,
- domain1: `get${domain}`,
- domain2: `try${domain}`,
- domain3: `use${domain}`,
- },
- });
+ const response = await getDomainSearchAvailability(domain);
return NextResponse.json(response);
},
diff --git a/apps/web/lib/api/domains/finalize-premium-domain-registration.ts b/apps/web/lib/api/domains/finalize-premium-domain-registration.ts
new file mode 100644
index 0000000000..52492d0178
--- /dev/null
+++ b/apps/web/lib/api/domains/finalize-premium-domain-registration.ts
@@ -0,0 +1,146 @@
+import { createLink } from "@/lib/api/links";
+import { registerDomain } from "@/lib/dynadot/register-domain";
+import { searchDomainsAvailability } from "@/lib/dynadot/search-domains";
+import { prisma } from "@/lib/prisma";
+import { sendBatchEmail } from "@dub/email";
+import DomainRegistered from "@dub/email/templates/domain-registered";
+import { DEFAULT_LINK_PROPS } from "@dub/utils";
+import { addDomainToVercel } from "./add-domain-vercel";
+import { configureVercelNameservers } from "./configure-vercel-nameservers";
+import { markDomainAsDeleted } from "./mark-domain-deleted";
+
+export async function finalizePremiumDomainRegistration({
+ domain,
+ workspaceId,
+}: {
+ domain: string;
+ workspaceId: string;
+}) {
+ const workspace = await prisma.project.findUniqueOrThrow({
+ where: { id: workspaceId },
+ select: {
+ id: true,
+ slug: true,
+ users: {
+ where: { role: "owner" },
+ select: { userId: true },
+ take: 1,
+ },
+ },
+ });
+
+ const userId = workspace.users[0]?.userId;
+ if (!userId) {
+ return `No workspace owner found to finalize registration for ${domain}.`;
+ }
+
+ const existingDomain = await prisma.domain.findUnique({
+ where: {
+ slug: domain,
+ verified: true,
+ },
+ });
+
+ if (existingDomain) {
+ return `Domain ${domain} is already registered, skipping...`;
+ }
+
+ const searchResults = await searchDomainsAvailability({
+ domains: { domain0: domain },
+ });
+ const domainStatus = searchResults[0];
+
+ const [response, totalDomains, matchingUnverifiedDomain] = await Promise.all([
+ registerDomain({ domain }),
+ prisma.domain.count({
+ where: {
+ projectId: workspace.id,
+ },
+ }),
+ prisma.domain.findFirst({
+ where: {
+ slug: domain,
+ verified: false,
+ },
+ include: {
+ registeredDomain: true,
+ },
+ }),
+ ]);
+
+ if (matchingUnverifiedDomain) {
+ await markDomainAsDeleted({
+ domain: matchingUnverifiedDomain.slug,
+ });
+ }
+
+ await Promise.allSettled([
+ prisma.domain.create({
+ data: {
+ projectId: workspace.id,
+ slug: domain,
+ verified: true,
+ lastChecked: new Date(),
+ primary: totalDomains === 0,
+ registeredDomain: {
+ create: {
+ slug: domain,
+ expiresAt: new Date(response.expiration || ""),
+ projectId: workspace.id,
+ renewalFee: domainStatus.prices?.renewal ?? 1200,
+ },
+ },
+ },
+ }),
+ createLink({
+ ...DEFAULT_LINK_PROPS,
+ domain,
+ key: "_root",
+ url: "",
+ tags: undefined,
+ userId,
+ projectId: workspace.id,
+ }),
+ addDomainToVercel(domain).then(() => configureVercelNameservers(domain)),
+ sendDomainRegisteredEmails({ workspace, domain }),
+ ]);
+
+ return `Premium domain ${domain} registered successfully.`;
+}
+
+export const sendDomainRegisteredEmails = async ({
+ workspace,
+ domain,
+}: {
+ workspace: { id: string; slug: string };
+ domain: string;
+}) => {
+ const workspaceWithOwner = await prisma.project.findUniqueOrThrow({
+ where: {
+ id: workspace.id,
+ },
+ include: {
+ users: {
+ where: {
+ role: "owner",
+ },
+ select: {
+ user: true,
+ },
+ },
+ },
+ });
+
+ return await sendBatchEmail(
+ workspaceWithOwner.users.map(({ user }) => ({
+ variant: "notifications",
+ to: user.email!,
+ subject: "Your premium .link domain has been registered!",
+ react: DomainRegistered({
+ email: user.email!,
+ domain,
+ workspaceSlug: workspace.slug,
+ }),
+ })),
+ );
+};
diff --git a/apps/web/lib/api/domains/get-domain-search-availability.ts b/apps/web/lib/api/domains/get-domain-search-availability.ts
new file mode 100644
index 0000000000..a1fcd23b85
--- /dev/null
+++ b/apps/web/lib/api/domains/get-domain-search-availability.ts
@@ -0,0 +1,32 @@
+import { searchDomainsAvailability } from "@/lib/dynadot/search-domains";
+import { prisma } from "@/lib/prisma";
+
+export async function getDomainSearchAvailability(domain: string) {
+ const domainOnDub = await prisma.domain.findUnique({
+ where: {
+ slug: domain,
+ verified: true,
+ },
+ });
+
+ if (domainOnDub) {
+ return [
+ {
+ domain: domainOnDub.slug,
+ available: false,
+ premium: false,
+ prices: null,
+ price: null,
+ },
+ ];
+ }
+
+ return searchDomainsAvailability({
+ domains: {
+ domain0: domain,
+ domain1: `get${domain}`,
+ domain2: `try${domain}`,
+ domain3: `use${domain}`,
+ },
+ });
+}
diff --git a/apps/web/lib/api/domains/initiate-premium-domain-registration.ts b/apps/web/lib/api/domains/initiate-premium-domain-registration.ts
new file mode 100644
index 0000000000..78504536df
--- /dev/null
+++ b/apps/web/lib/api/domains/initiate-premium-domain-registration.ts
@@ -0,0 +1,165 @@
+import { createId } from "@/lib/api/create-id";
+import { parseRegisteredDomainSlugs } from "@/lib/api/domains/is-domain-registration-invoice";
+import { DubApiError } from "@/lib/api/errors";
+import { searchDomainsAvailability } from "@/lib/dynadot/search-domains";
+import { prisma } from "@/lib/prisma";
+import { createPaymentIntent } from "@/lib/stripe/create-payment-intent";
+import { isWorkspaceBillingTrialActive } from "@dub/utils";
+import { Project } from "@prisma/client";
+
+export async function initiatePremiumDomainRegistration({
+ domain,
+ workspace,
+ skipWorkspaceChecks = false,
+}: {
+ domain: string;
+ workspace: Pick<
+ Project,
+ "id" | "slug" | "plan" | "stripeId" | "trialEndsAt" | "invoicePrefix"
+ >;
+ skipWorkspaceChecks?: boolean;
+}) {
+ if (!skipWorkspaceChecks) {
+ if (workspace.plan === "free") {
+ throw new DubApiError({
+ code: "forbidden",
+ message: "Free workspaces cannot register .link domains.",
+ });
+ }
+
+ if (isWorkspaceBillingTrialActive(workspace.trialEndsAt)) {
+ throw new DubApiError({
+ code: "forbidden",
+ message: "You cannot register a .link domain during your free trial.",
+ });
+ }
+ }
+
+ if (!workspace.stripeId) {
+ throw new DubApiError({
+ code: "forbidden",
+ message:
+ "You cannot register a premium .link domain until you add a payment method.",
+ });
+ }
+
+ const [searchResults, existingDomain] = await Promise.all([
+ searchDomainsAvailability({
+ domains: { domain0: domain },
+ }),
+ prisma.domain.findUnique({
+ where: {
+ slug: domain,
+ verified: true,
+ },
+ }),
+ ]);
+
+ if (existingDomain) {
+ throw new DubApiError({
+ code: "conflict",
+ message: `Domain "${domain}" is already registered.`,
+ });
+ }
+
+ const domainStatus = searchResults[0];
+
+ if (!domainStatus?.available) {
+ throw new DubApiError({
+ code: "bad_request",
+ message: `Domain "${domain}" is not available for registration.`,
+ });
+ }
+
+ if (!domainStatus.premium || !domainStatus.prices?.registration) {
+ throw new DubApiError({
+ code: "bad_request",
+ message: `Domain "${domain}" is not a premium domain.`,
+ });
+ }
+
+ const registrationPriceCents = domainStatus.prices.registration;
+
+ const outcome = await prisma.$transaction(async (tx) => {
+ const pendingInvoices = await tx.invoice.findMany({
+ where: {
+ workspaceId: workspace.id,
+ type: "domainRenewal",
+ status: "processing",
+ },
+ select: {
+ registeredDomains: true,
+ },
+ });
+
+ const hasPendingForSlug = pendingInvoices.some((inv) =>
+ parseRegisteredDomainSlugs(inv.registeredDomains).includes(domain),
+ );
+
+ if (hasPendingForSlug) {
+ return { ok: false as const };
+ }
+
+ const totalInvoices = await tx.invoice.count({
+ where: {
+ workspaceId: workspace.id,
+ },
+ });
+ const paddedNumber = String(totalInvoices + 1).padStart(4, "0");
+ const invoiceNumber = `${workspace.invoicePrefix}-${paddedNumber}`;
+
+ const invoice = await tx.invoice.create({
+ data: {
+ id: createId({ prefix: "inv_" }),
+ workspaceId: workspace.id,
+ number: invoiceNumber,
+ type: "domainRenewal",
+ amount: registrationPriceCents,
+ total: registrationPriceCents,
+ registeredDomains: [domain],
+ },
+ });
+
+ return { ok: true as const, invoice, registrationPriceCents };
+ });
+
+ if (!outcome.ok) {
+ throw new DubApiError({
+ code: "conflict",
+ message:
+ "A premium domain registration charge is already processing for this domain. Wait for it to complete or fail before retrying.",
+ });
+ }
+
+ const { invoice } = outcome;
+
+ const { paymentIntent } = await createPaymentIntent({
+ stripeId: workspace.stripeId,
+ amount: registrationPriceCents,
+ invoiceId: invoice.id,
+ statementDescriptor: "DUB.CO DOMAIN REG",
+ description: `Premium domain registration (${domain})`,
+ idempotencyKey: `${invoice.id}-${invoice.failedAttempts}`,
+ });
+
+ if (!paymentIntent) {
+ await prisma.invoice.update({
+ where: { id: invoice.id },
+ data: {
+ status: "failed",
+ failedReason: "Could not charge the workspace payment method.",
+ },
+ });
+
+ throw new DubApiError({
+ code: "unprocessable_entity",
+ message: "Could not charge the workspace payment method.",
+ });
+ }
+
+ return {
+ invoiceId: invoice.id,
+ paymentIntentStatus: paymentIntent.status,
+ registrationPriceCents,
+ };
+}
diff --git a/apps/web/lib/api/domains/is-domain-registration-invoice.ts b/apps/web/lib/api/domains/is-domain-registration-invoice.ts
new file mode 100644
index 0000000000..290fa8a977
--- /dev/null
+++ b/apps/web/lib/api/domains/is-domain-registration-invoice.ts
@@ -0,0 +1,29 @@
+import { prisma } from "@/lib/prisma";
+
+export function parseRegisteredDomainSlugs(
+ registeredDomains: unknown,
+): string[] {
+ if (!Array.isArray(registeredDomains)) return [];
+ return registeredDomains.filter((d): d is string => typeof d === "string");
+}
+
+export async function isDomainRegistrationInvoice({
+ slugs,
+ workspaceId,
+}: {
+ slugs: string[];
+ workspaceId: string;
+}): Promise<boolean> {
+ // premium domains can only be registered/renewed one at a time
+ if (slugs.length !== 1) return false;
+
+ const registeredDomain = await prisma.registeredDomain.findFirst({
+ where: {
+ slug: slugs[0],
+ projectId: workspaceId,
+ },
+ });
+
+ // if registered domain exists, it's a renewal (not a new domain registration)
+ return registeredDomain ? false : true;
+}
diff --git a/apps/web/lib/api/domains/normalize-domain-input.ts b/apps/web/lib/api/domains/normalize-domain-input.ts
new file mode 100644
index 0000000000..9b2fc29c91
--- /dev/null
+++ b/apps/web/lib/api/domains/normalize-domain-input.ts
@@ -0,0 +1,21 @@
+export const normalizeDomainInput = (raw: string): string => {
+ let s = raw.trim().toLowerCase();
+ if (!s) {
+ return s;
+ }
+ try {
+ if (s.includes("://")) {
+ const url = new URL(s);
+ s = url.hostname;
+ } else if (s.includes("/")) {
+ const url = new URL(`https://${s}`);
+ s = url.hostname;
+ }
+ } catch {
+ // keep s as typed
+ }
+ if (s.startsWith("www.")) {
+ s = s.slice(4);
+ }
+ return s;
+};
diff --git a/apps/web/lib/dynadot/calculate-domain-price.ts b/apps/web/lib/dynadot/calculate-domain-price.ts
new file mode 100644
index 0000000000..40bc4846ea
--- /dev/null
+++ b/apps/web/lib/dynadot/calculate-domain-price.ts
@@ -0,0 +1,30 @@
+import { DYNADOT_DOMAIN_DEFAULT_RENEWAL_FEE_CENTS } from "./constants";
+
+const REGISTRATION_PRICE_REGEX = /Registration Price:\s*([\d.]+)/i;
+const RENEWAL_PRICE_REGEX = /Renewal price:\s*([\d.]+)/i;
+
+// Apply 4% markup and round up to the nearest $10 (e.g. $273 → $280)
+// Minimum DYNADOT_DOMAIN_DEFAULT_RENEWAL_FEE_CENTS
+function calculateDomainPrice(basePriceUsd: number): number {
+ const withMarkup = basePriceUsd * 1.04;
+ const rounded = Math.ceil(withMarkup / 10) * 10;
+ const toCents = rounded * 100;
+
+ return Math.max(toCents, DYNADOT_DOMAIN_DEFAULT_RENEWAL_FEE_CENTS);
+}
+
+export function parseRegistrationPriceUsdCents(
+ price: string | null | undefined,
+): number | null {
+ if (!price) return null;
+ const match = price.match(REGISTRATION_PRICE_REGEX);
+ return match ? calculateDomainPrice(parseFloat(match[1])) : null;
+}
+
+export function parseRenewalPriceUsdCents(
+ price: string | null | undefined,
+): number | null {
+ if (!price) return null;
+ const match = price.match(RENEWAL_PRICE_REGEX);
+ return match ? calculateDomainPrice(parseFloat(match[1])) : null;
+}
diff --git a/apps/web/lib/dynadot/constants.ts b/apps/web/lib/dynadot/constants.ts
index 3dd85b667a..e5403626e2 100644
--- a/apps/web/lib/dynadot/constants.ts
+++ b/apps/web/lib/dynadot/constants.ts
@@ -3,6 +3,8 @@ export const DYNADOT_BASE_URL =
export const DYNADOT_API_KEY = process.env.DYNADOT_API_KEY || "";
export const DYNADOT_COUPON = process.env.DYNADOT_COUPON || "";
+export const DYNADOT_DOMAIN_DEFAULT_RENEWAL_FEE_CENTS = 1200;
+
// TODO: this logic is hard-coded for now, but we'll make it dynamic in the future
export const DOMAIN_REGISTRATION_ELIGIBLE_WORKSPACES = [
"clrei1gld0002vs9mzn93p8ik",
diff --git a/apps/web/lib/dynadot/register-domain.ts b/apps/web/lib/dynadot/register-domain.ts
index befceac763..95d2aab412 100644
--- a/apps/web/lib/dynadot/register-domain.ts
+++ b/apps/web/lib/dynadot/register-domain.ts
@@ -29,6 +29,15 @@ const ERROR_CODES = {
};
export const registerDomain = async ({ domain }: { domain: string }) => {
+ // mock response for development
+ if (process.env.NODE_ENV === "development") {
+ return RegisterDomainSchema.parse({
+ domain,
+ status: "success",
+ expiration: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).getTime(),
+ });
+ }
+
const searchParams = new URLSearchParams({
domain,
command: "register",
diff --git a/apps/web/lib/dynadot/search-domains.ts b/apps/web/lib/dynadot/search-domains.ts
index 66bb5ff4da..b3bf5a0d1d 100644
--- a/apps/web/lib/dynadot/search-domains.ts
+++ b/apps/web/lib/dynadot/search-domains.ts
@@ -1,6 +1,10 @@
import * as z from "zod/v4";
import { DubApiError } from "../api/errors";
import { DomainStatusSchema } from "../zod/schemas/domains";
+import {
+ parseRegistrationPriceUsdCents,
+ parseRenewalPriceUsdCents,
+} from "./calculate-domain-price";
import { DYNADOT_API_KEY, DYNADOT_BASE_URL } from "./constants";
const schema = z.object({
@@ -56,13 +60,25 @@ export const searchDomainsAvailability = async ({
}
const result = data.SearchResponse.SearchResults.map((result) => {
- const premium = result.Price && /is\s+a Premium Domain/.test(result.Price);
+ const premium = Boolean(
+ result.Price && /is\s+a Premium Domain/.test(result.Price),
+ );
+ const registrationPriceUsdCents = parseRegistrationPriceUsdCents(
+ result.Price,
+ );
+ const renewalPriceUsdCents = parseRenewalPriceUsdCents(result.Price);
return {
domain: result.DomainName,
- available: result.Available === "yes" && !premium,
- price: result.Price,
+ available: result.Available === "yes",
premium,
+ prices: result.Available
+ ? {
+ registration: premium ? registrationPriceUsdCents : 0,
+ renewal: renewalPriceUsdCents,
+ }
+ : null,
+ price: "Deprecated: Use `prices` instead.",
};
});
diff --git a/apps/web/lib/zod/schemas/domains.ts b/apps/web/lib/zod/schemas/domains.ts
index 7846875106..2da70b83a2 100644
--- a/apps/web/lib/zod/schemas/domains.ts
+++ b/apps/web/lib/zod/schemas/domains.ts
@@ -211,11 +211,30 @@ export const searchDomainSchema = z.object({
export const DomainStatusSchema = z.object({
domain: z.string().describe("The domain name."),
available: z.boolean().describe("Whether the domain is available."),
- price: z.string().nullable().describe("The price description."),
premium: z
.boolean()
.nullable()
.describe("Whether the domain is a premium domain."),
+ prices: z
+ .object({
+ registration: z
+ .number()
+ .nullable()
+ .describe("The domain's registration price in USD cents."),
+ renewal: z
+ .number()
+ .nullable()
+ .describe("The domain's renewal price in USD cents."),
+ })
+ .nullable()
+ .describe(
+ "Price details for the domain. Will be null if the domain is not available.",
+ ),
+ price: z
+ .string()
+ .nullable()
+ .describe("Deprecated: Use `prices` instead.")
+ .meta({ deprecated: true }),
});
export const RegisterDomainSchema = z.object({
diff --git a/apps/web/tests/domains/index.test.ts b/apps/web/tests/domains/index.test.ts
index e0dcf3180d..0e9a654d68 100644
--- a/apps/web/tests/domains/index.test.ts
+++ b/apps/web/tests/domains/index.test.ts
@@ -137,14 +137,19 @@ describe.sequential("/domains/**", async () => {
{
domain: domains[0],
available: false,
- price: null,
premium: null,
+ prices: null,
+ price: null,
},
{
domain: domains[1],
available: true,
- price: expect.any(String),
premium: expect.any(Boolean),
+ prices: {
+ registration: expect.any(Number),
+ renewal: expect.any(Number),
+ },
+ price: expect.any(String),
},
]);
});
diff --git a/apps/web/ui/domains/register-domain-form.tsx b/apps/web/ui/domains/register-domain-form.tsx
index db28213d0c..9526fa3622 100644
--- a/apps/web/ui/domains/register-domain-form.tsx
+++ b/apps/web/ui/domains/register-domain-form.tsx
@@ -82,7 +82,7 @@ export function RegisterDomainForm({
}, [debouncedSlug]);
// Register domain
- const registerDomain = async (domain: string) => {
+ const handleSubmit = async (domain: string) => {
setIsRegistering(true);
const baseUrl = saveOnly
@@ -134,7 +134,7 @@ export function RegisterDomainForm({
// prevent the submission event from propagating to the parent form (in the link builder)
e.stopPropagation();
if (searchedDomain && searchedDomain.available) {
- await registerDomain(searchedDomain.domain);
+ await handleSubmit(searchedDomain.domain);
}
}}
>
@@ -271,7 +271,7 @@ export function RegisterDomainForm({
<Button
text="Claim domain"
className="h-8 w-fit"
- onClick={() => registerDomain(alternative.domain)}
+ onClick={() => handleSubmit(alternative.domain)}
disabled={
isRegistering ||
(workspace.plan === "free" && !saveOnly)
diff --git a/packages/email/src/templates/domain-registered.tsx b/packages/email/src/templates/domain-registered.tsx
new file mode 100644
index 0000000000..2b91337dba
--- /dev/null
+++ b/packages/email/src/templates/domain-registered.tsx
@@ -0,0 +1,75 @@
+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 DomainRegistered({
+ email = "[email protected]",
+ domain = "dub.link",
+ workspaceSlug = "dub",
+}: {
+ email: string;
+ domain: string;
+ workspaceSlug: string;
+}) {
+ return (
+ <Html>
+ <Head />
+ <Preview>Your premium .link domain has been registered!</Preview>
+ <Tailwind>
+ <Body className="mx-auto my-auto bg-white font-sans">
+ <Container className="mx-auto my-10 max-w-[600px] rounded border border-solid border-neutral-200 px-10 py-5">
+ <Section className="mt-8">
+ <Img src={DUB_WORDMARK} height="32" alt="Dub" />
+ </Section>
+ <Heading className="mx-0 my-7 p-0 text-lg font-medium text-black">
+ Your premium .link domain has been registered!
+ </Heading>
+ <Text className="text-sm leading-6 text-black">
+ Your premium domain{" "}
+ <code className="text-purple-600">{domain}</code> has been
+ successfully registered 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">
+ <Link
+ className="rounded-lg 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 is usually completed within 1 hour, but can
+ sometimes take up to 12 hours (for the DNS records and SSL certs
+ to fully propagate).
+ </Text>
+ <Text className="text-sm leading-6 text-black">
+ If your domain is not active after 12 hours, please reply to this
+ email and we will look into it.
+ </Text>
+ <Footer email={email} />
+ </Container>
+ </Body>
+ </Tailwind>
+ </Html>
+ );
+}