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.

Fix accidental domain removal from Vercel

Steven Tey94a7374c124e
diff --git a/apps/web/lib/api/domains/remove-domain-vercel.ts b/apps/web/lib/api/domains/remove-domain-vercel.ts
index cbd3f5a742..157bc6108e 100644
--- a/apps/web/lib/api/domains/remove-domain-vercel.ts
+++ b/apps/web/lib/api/domains/remove-domain-vercel.ts
@@ -3,7 +3,7 @@ import { getApexDomain } from "@dub/utils";
export const removeDomainFromVercel = async (domain: string) => {
const apexDomain = getApexDomain(`https://${domain}`);
- const domainCount = await prisma.domain.count({
+ const domains = await prisma.domain.findMany({
where: {
OR: [
{
@@ -16,10 +16,13 @@ export const removeDomainFromVercel = async (domain: string) => {
},
],
},
+ select: {
+ slug: true,
+ },
});
- if (domainCount > 1) {
- // the apex domain is being used by other domains on Dub
- // so we should only remove it from our Vercel project
+ // if there are other subdomains or the apex domain itself is in use
+ // so we should only remove it from our Vercel project
+ if (domains.filter((d) => d.slug !== domain).length > 0) {
return await fetch(
`https://api.vercel.com/v9/projects/${process.env.PROJECT_ID_VERCEL}/domains/${domain.toLowerCase()}?teamId=${process.env.TEAM_ID_VERCEL}`,
{
@@ -30,8 +33,8 @@ export const removeDomainFromVercel = async (domain: string) => {
},
).then((res) => res.json());
} else {
- // this is the only domain using this apex domain
- // so we can remove it entirely from our Vercel team
+ // if this is the only domain that is in use
+ // we can remove it entirely from our Vercel team
return await fetch(
`https://api.vercel.com/v6/domains/${domain.toLowerCase()}?teamId=${process.env.TEAM_ID_VERCEL}`,
{