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 refresh domain

Steven Teyc21068da04de
diff --git a/apps/web/app/admin.dub.co/actions.ts b/apps/web/app/admin.dub.co/actions.ts
index a507d01659..3dd79465ff 100644
--- a/apps/web/app/admin.dub.co/actions.ts
+++ b/apps/web/app/admin.dub.co/actions.ts
@@ -1,5 +1,6 @@
"use server";
+import { addDomainToVercel, removeDomainFromVercel } from "@/lib/api/domains";
import { deleteProjectAdmin } from "@/lib/api/projects";
import { getSession, hashToken } from "@/lib/auth";
import { unsubscribe } from "@/lib/flodesk";
@@ -217,3 +218,20 @@ export async function banUser(data: FormData) {
return true;
}
+
+export async function refreshDomain(data: FormData) {
+ const domain = data.get("domain") as string;
+
+ if (!(await isAdmin())) {
+ return {
+ error: "Unauthorized",
+ };
+ }
+
+ const remove = await removeDomainFromVercel(domain);
+ const add = await addDomainToVercel(domain);
+
+ console.log({ remove, add });
+
+ return true;
+}
diff --git a/apps/web/app/admin.dub.co/components/refresh-domain.tsx b/apps/web/app/admin.dub.co/components/refresh-domain.tsx
new file mode 100644
index 0000000000..4a8afc11f0
--- /dev/null
+++ b/apps/web/app/admin.dub.co/components/refresh-domain.tsx
@@ -0,0 +1,53 @@
+"use client";
+
+import { Button, LoadingSpinner } from "@dub/ui";
+import { cn } from "@dub/utils";
+import { useState } from "react";
+import { useFormStatus } from "react-dom";
+import { toast } from "sonner";
+import { banUser, getUserOrProjectOwner, refreshDomain } from "../actions";
+import UserInfo, { UserInfoProps } from "./user-info";
+
+export default function RefreshDomain() {
+ const [data, setData] = useState<UserInfoProps | null>(null);
+
+ return (
+ <div className="flex flex-col space-y-5">
+ <form
+ action={(data) =>
+ refreshDomain(data).then(() => {
+ toast.success("Domain refreshed");
+ })
+ }
+ >
+ <Form />
+ </form>
+ </div>
+ );
+}
+
+const Form = () => {
+ const { pending } = useFormStatus();
+
+ return (
+ <div className="relative flex w-full rounded-md shadow-sm">
+ <input
+ name="domain"
+ id="domain"
+ type="text"
+ required
+ disabled={pending}
+ autoComplete="off"
+ className={cn(
+ "block w-full rounded-md border-gray-300 text-sm text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500",
+ pending && "bg-gray-100",
+ )}
+ placeholder="acme.com"
+ aria-invalid="true"
+ />
+ {pending && (
+ <LoadingSpinner className="absolute inset-y-0 right-2 my-auto h-full w-5 text-gray-400" />
+ )}
+ </div>
+ );
+};
diff --git a/apps/web/app/admin.dub.co/page.tsx b/apps/web/app/admin.dub.co/page.tsx
index 8483d031b9..1ef9479abf 100644
--- a/apps/web/app/admin.dub.co/page.tsx
+++ b/apps/web/app/admin.dub.co/page.tsx
@@ -1,6 +1,7 @@
import { constructMetadata } from "@dub/utils";
import ImpersonateProject from "./components/impersonate-project";
import ImpersonateUser from "./components/impersonate-user";
+import RefreshDomain from "./components/refresh-domain";
export const metadata = constructMetadata({
title: "Dub Admin",
@@ -22,6 +23,13 @@ export default function AdminPage() {
</p>
<ImpersonateProject />
</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-gray-500">
+ Remove and re-add domain from Vercel
+ </p>
+ <RefreshDomain />
+ </div>
</div>
);
}
diff --git a/apps/web/lib/api/domains.ts b/apps/web/lib/api/domains.ts
index c0f05abde2..ee6fe72dc4 100644
--- a/apps/web/lib/api/domains.ts
+++ b/apps/web/lib/api/domains.ts
@@ -88,7 +88,7 @@ export const removeDomainFromVercel = async (domain: string) => {
},
});
if (domainCount > 1) {
- // the apex domain is being used by other domains
+ // the apex domain is being used by other domains on Dub
// so we should only remove it from our Vercel project
return await fetch(
`https://api.vercel.com/v9/projects/${process.env.PROJECT_ID_VERCEL}/domains/${domain}?teamId=${process.env.TEAM_ID_VERCEL}`,