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 delete

Kiran Kdeac75d6da05
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.ts
index 3e0aa77b7b..3d8981a1b0 100644
--- a/apps/web/app/api/links/[linkId]/route.ts
+++ b/apps/web/app/api/links/[linkId]/route.ts
@@ -141,6 +141,25 @@ export const PUT = PATCH;
// DELETE /api/links/[linkId] – delete a link
export const DELETE = withWorkspace(async ({ headers, link }) => {
+ if (link?.key === "_root") {
+ const linksCount = await prisma.link.count({
+ where: {
+ domain: link.domain,
+ NOT: {
+ key: "_root",
+ },
+ },
+ });
+
+ if (linksCount > 0) {
+ throw new DubApiError({
+ code: "forbidden",
+ message:
+ "You cannot delete the root link. Please delete the domain instead.",
+ });
+ }
+ }
+
await deleteLink(link!.id);
return NextResponse.json(