The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Recheck the network ban under the application lock
Rafibdf3c86450e3
diff --git a/apps/web/lib/actions/partners/create-program-application.ts b/apps/web/lib/actions/partners/create-program-application.tsindex 3abc79cf51..d90f6e6bec 100644--- a/apps/web/lib/actions/partners/create-program-application.ts+++ b/apps/web/lib/actions/partners/create-program-application.ts@@ -53,6 +53,9 @@ import { actionClient } from "../safe-action";export type PartnerData = { name: string; country?: string };+const NETWORK_BAN_ERROR =+ "Your account is banned from the Dub Partner Network, so you can't apply to programs. Please contact [email protected] if you think this is a mistake.";+interface Response {programApplicationId: string;programEnrollmentId?: string;@@ -193,9 +196,7 @@ export const createProgramApplicationAction = actionClientif (existingPartner) {if (existingPartner.networkStatus === "banned") {- throw new Error(- "Your account is banned from the Dub Partner Network, so you can't apply to programs. Please contact [email protected] if you think this is a mistake.",- );+ throw new Error(NETWORK_BAN_ERROR);}// for in-app applications from existing partners, we need to check@@ -302,7 +303,14 @@ async function createApplicationAndEnrollment({async (tx) => {// Serializes concurrent applications from the same partner so the// checks below cannot be raced (MySQL has no partial unique index so we can't restrict this on DB level).- await tx.$queryRaw`SELECT id FROM Partner WHERE id = ${partner.id} FOR UPDATE`;+ const [lockedPartner] = await tx.$queryRaw<+ Pick<Partner, "networkStatus">[]+ >`SELECT networkStatus FROM Partner WHERE id = ${partner.id} FOR UPDATE`;++ // Recheck under the lock, in case a ban was saved after the first read+ if (lockedPartner?.networkStatus === "banned") {+ throw new Error(NETWORK_BAN_ERROR);+ }const enrollment = await tx.programEnrollment.findUnique({where: {