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.

address CR feedback

Steven Teyff179fc850b4
diff --git a/apps/web/lib/api/links/plan-features-check.ts b/apps/web/lib/api/links/plan-features-check.ts
index fb1fbe7bf4..4ad1ebad8e 100644
--- a/apps/web/lib/api/links/plan-features-check.ts
+++ b/apps/web/lib/api/links/plan-features-check.ts
@@ -47,13 +47,7 @@ export const proFeaturesCheck = (payload: NewLinkProps) => {
};
export const businessFeaturesCheck = (payload: NewLinkProps) => {
- const { domain, testVariants, trackConversion } = payload;
-
- if (domain && domain.endsWith(".dub.link")) {
- throw new Error(
- "You can only use .dub.link domains on a Business plan and above. Upgrade to Business to use this domain.",
- );
- }
+ const { testVariants, trackConversion } = payload;
if (testVariants || trackConversion) {
const businessFeaturesString = combineWords(
@@ -68,3 +62,11 @@ export const businessFeaturesCheck = (payload: NewLinkProps) => {
);
}
};
+
+export const dubLinkSubdomainCheck = (domain: string) => {
+ if (domain.endsWith(".dub.link")) {
+ throw new Error(
+ "You can only use .dub.link domains on a Business plan and above. Upgrade to Business to use this domain.",
+ );
+ }
+};
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.ts
index 38d0b7096c..fc7054590b 100644
--- a/apps/web/lib/api/links/process-link.ts
+++ b/apps/web/lib/api/links/process-link.ts
@@ -18,7 +18,11 @@ import {
} from "@dub/utils";
import { Project, WorkspaceRole } from "@prisma/client";
import { combineTagIds } from "../tags/combine-tag-ids";
-import { businessFeaturesCheck, proFeaturesCheck } from "./plan-features-check";
+import {
+ businessFeaturesCheck,
+ dubLinkSubdomainCheck,
+ proFeaturesCheck,
+} from "./plan-features-check";
import { keyChecks, processKey } from "./utils";
export async function processLink<T extends Record<string, any>>({
@@ -114,6 +118,17 @@ export async function processLink<T extends Record<string, any>>({
};
}
+ const domains = workspace
+ ? await prisma.domain.findMany({
+ where: { projectId: workspace.id },
+ })
+ : [];
+
+ // if domain is not defined, set it to the workspace's primary domain
+ if (!domain) {
+ domain = domains?.find((d) => d.primary)?.slug || "dub.sh";
+ }
+
// free plan restrictions
if (!workspace || workspace.plan === "free") {
if (key === "_root" && url) {
@@ -125,8 +140,9 @@ export async function processLink<T extends Record<string, any>>({
};
}
try {
- businessFeaturesCheck(payload);
+ dubLinkSubdomainCheck(domain);
proFeaturesCheck(payload);
+ businessFeaturesCheck(payload);
} catch (error) {
return {
link: payload,
@@ -136,6 +152,7 @@ export async function processLink<T extends Record<string, any>>({
}
} else if (workspace.plan === "pro") {
try {
+ dubLinkSubdomainCheck(domain);
businessFeaturesCheck(payload);
} catch (error) {
return {
@@ -154,17 +171,6 @@ export async function processLink<T extends Record<string, any>>({
};
}
- const domains = workspace
- ? await prisma.domain.findMany({
- where: { projectId: workspace.id },
- })
- : [];
-
- // if domain is not defined, set it to the workspace's primary domain
- if (!domain) {
- domain = domains?.find((d) => d.primary)?.slug || "dub.sh";
- }
-
// checks for dub.sh and dub.link links
if (domain === "dub.sh" || domain === "dub.link") {
// for dub.link: check if workspace plan is pro+