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.

checkIfKeyExists

Steven Tey7939d6665c39
diff --git a/apps/web/app/api/programs/[programId]/partners/route.ts b/apps/web/app/api/programs/[programId]/partners/route.ts
index 98aac13fca..5c3320c2cb 100644
--- a/apps/web/app/api/programs/[programId]/partners/route.ts
+++ b/apps/web/app/api/programs/[programId]/partners/route.ts
@@ -3,6 +3,7 @@ import { createLink } from "@/lib/api/links";
import { enrollPartner } from "@/lib/api/partners/enroll-partner";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
+import { checkIfKeyExists } from "@/lib/planetscale";
import {
createPartnerSchema,
EnrolledPartnerSchema,
@@ -85,6 +86,15 @@ export const POST = withWorkspace(async ({ workspace, params, req }) => {
});
}
+ const linkExists = await checkIfKeyExists(program.domain, username);
+
+ if (linkExists) {
+ throw new DubApiError({
+ code: "conflict",
+ message: "This username is already in use. Choose a different one.",
+ });
+ }
+
const link = await createLink({
projectId: workspace.id,
domain: program.domain,