The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
API - Partner shouldn't be able to update the default links
Kiran K11460952da4f
diff --git a/apps/web/app/(ee)/api/embed/referrals/links/[linkId]/route.ts b/apps/web/app/(ee)/api/embed/referrals/links/[linkId]/route.tsindex 4120bc084a..a644ea3fd9 100644--- a/apps/web/app/(ee)/api/embed/referrals/links/[linkId]/route.ts+++ b/apps/web/app/(ee)/api/embed/referrals/links/[linkId]/route.ts@@ -5,7 +5,6 @@ import { parseRequestBody } from "@/lib/api/utils";import { withReferralsEmbedToken } from "@/lib/embed/referrals/auth";import { createPartnerLinkSchema } from "@/lib/zod/schemas/partners";import { ReferralsEmbedLinkSchema } from "@/lib/zod/schemas/referrals-embed";-import { getUrlWithoutUTMParams } from "@dub/utils";import { NextResponse } from "next/server";// PATCH /api/embed/referrals/links/[linkId] - update a link for a partner@@ -39,25 +38,11 @@ export const PATCH = withReferralsEmbedToken(});}- // prevent updating the default partner link- const defaultLinks = links.filter(({ url }) =>- group.defaultLinks.find(- (defaultLink) =>- defaultLink.url === getUrlWithoutUTMParams(url) &&- defaultLink.url === getUrlWithoutUTMParams(link.url),- ),- );-- if (defaultLinks.length > 0) {- const defaultLink = defaultLinks[0];-- if (defaultLink?.id === link.id) {- throw new DubApiError({- code: "forbidden",- message:- "You cannot update the default partner link. Please contact us if you think this is an error.",- });- }+ if (link.partnerGroupDefaultLinkId) {+ throw new DubApiError({+ code: "forbidden",+ message: "This is your default partner link and cannot be updated.",+ });}validatePartnerLinkUrl({ group, url });diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/links/[linkId]/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/links/[linkId]/route.tsindex 1ec11cc60c..a818afdaf6 100644--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/links/[linkId]/route.ts+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/links/[linkId]/route.ts@@ -6,7 +6,6 @@ import { parseRequestBody } from "@/lib/api/utils";import { withPartnerProfile } from "@/lib/auth/partner";import { NewLinkProps } from "@/lib/types";import { createPartnerLinkSchema } from "@/lib/zod/schemas/partners";-import { getUrlWithoutUTMParams } from "@dub/utils";import { NextResponse } from "next/server";// PATCH /api/partner-profile/[programId]/links/[linkId] - update a link for a partner@@ -58,25 +57,11 @@ export const PATCH = withPartnerProfile(});}- // prevent updating the default partner link- const defaultLinks = links.filter(({ url }) =>- group.defaultLinks.find(- (defaultLink) =>- defaultLink.url === getUrlWithoutUTMParams(url) &&- defaultLink.url === getUrlWithoutUTMParams(link.url),- ),- );-- if (defaultLinks.length > 0) {- const defaultLink = defaultLinks[0];-- if (defaultLink?.id === link.id) {- throw new DubApiError({- code: "forbidden",- message:- "You cannot update the default partner link. Please contact us if you think this is an error.",- });- }+ if (link.partnerGroupDefaultLinkId) {+ throw new DubApiError({+ code: "forbidden",+ message: "This is your default partner link and cannot be updated.",+ });}validatePartnerLinkUrl({ group, url });diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex 9202618f43..dd1ae9fc59 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -293,7 +293,7 @@ export type ProcessedLinkProps = Omit<NewLinkProps, ProcessedLinkOverrides> &Pick<LinkProps, ProcessedLinkOverrides> & { userId?: LinkProps["userId"] } & {createdAt?: Date;id?: string;- partnerGroupDefaultLinkId?: string;+ partnerGroupDefaultLinkId?: string | null;};export const plans = [