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.

domainChecks → dubDomainChecks

Steven Tey572da7f6740c
diff --git a/apps/web/app/api/analytics/public-stats/route.ts b/apps/web/app/api/analytics/public-stats/route.ts
index 54033ab413..f45943e01c 100644
--- a/apps/web/app/api/analytics/public-stats/route.ts
+++ b/apps/web/app/api/analytics/public-stats/route.ts
@@ -17,7 +17,7 @@ export const GET = withWorkspace(async ({ searchParams, workspace }) => {
await getDomainOrThrow({
workspace,
domain,
- domainChecks: true,
+ dubDomainChecks: true,
});
const response = await getLinkViaEdge(domain, key);
@@ -32,7 +32,7 @@ export const PUT = withWorkspace(async ({ req, searchParams, workspace }) => {
await getDomainOrThrow({
workspace,
domain,
- domainChecks: true,
+ dubDomainChecks: true,
});
const response = await prisma.link.update({
diff --git a/apps/web/app/api/domains/[domain]/primary/route.ts b/apps/web/app/api/domains/[domain]/primary/route.ts
index 73a2effd40..8dbf7813a8 100644
--- a/apps/web/app/api/domains/[domain]/primary/route.ts
+++ b/apps/web/app/api/domains/[domain]/primary/route.ts
@@ -10,7 +10,7 @@ export const POST = withWorkspace(
const { slug: domain } = await getDomainOrThrow({
workspace,
domain: params.domain,
- domainChecks: true,
+ dubDomainChecks: true,
});
const [domainRecord] = await Promise.all([
diff --git a/apps/web/app/api/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.ts
index 4132207d9e..56c1513b92 100644
--- a/apps/web/app/api/domains/[domain]/route.ts
+++ b/apps/web/app/api/domains/[domain]/route.ts
@@ -23,7 +23,7 @@ export const GET = withWorkspace(async ({ workspace, params }) => {
const domainRecord = await getDomainOrThrow({
workspace,
domain: params.domain,
- domainChecks: true,
+ dubDomainChecks: true,
});
return NextResponse.json(DomainSchema.parse(domainRecord));
@@ -35,7 +35,7 @@ export const PATCH = withWorkspace(
const { slug: domain } = await getDomainOrThrow({
workspace,
domain: params.domain,
- domainChecks: true,
+ dubDomainChecks: true,
});
const {
@@ -135,7 +135,7 @@ export const DELETE = withWorkspace(
const { slug: domain } = await getDomainOrThrow({
workspace,
domain: params.domain,
- domainChecks: true,
+ dubDomainChecks: true,
});
await deleteDomainAndLinks(domain);
diff --git a/apps/web/app/api/domains/[domain]/transfer/route.ts b/apps/web/app/api/domains/[domain]/transfer/route.ts
index 48df87fdf6..f0951a0d4c 100644
--- a/apps/web/app/api/domains/[domain]/transfer/route.ts
+++ b/apps/web/app/api/domains/[domain]/transfer/route.ts
@@ -17,7 +17,7 @@ export const POST = withWorkspace(
const { slug: domain } = await getDomainOrThrow({
workspace,
domain: params.domain,
- domainChecks: true,
+ dubDomainChecks: true,
});
const { newWorkspaceId } = transferDomainBodySchema.parse(await req.json());
diff --git a/apps/web/app/api/domains/[domain]/verify/route.ts b/apps/web/app/api/domains/[domain]/verify/route.ts
index dc5d2e4899..c01cebec32 100644
--- a/apps/web/app/api/domains/[domain]/verify/route.ts
+++ b/apps/web/app/api/domains/[domain]/verify/route.ts
@@ -16,7 +16,7 @@ export const GET = withWorkspace(async ({ params, workspace }) => {
const { slug: domain } = await getDomainOrThrow({
workspace,
domain: params.domain,
- domainChecks: true,
+ dubDomainChecks: true,
});
let status: DomainVerificationStatusProps = "Valid Configuration";
diff --git a/apps/web/lib/api/domains/get-domain.ts b/apps/web/lib/api/domains/get-domain.ts
index 8e07b0c748..e81255d450 100644
--- a/apps/web/lib/api/domains/get-domain.ts
+++ b/apps/web/lib/api/domains/get-domain.ts
@@ -6,11 +6,11 @@ import { DubApiError } from "../errors";
export const getDomainOrThrow = async ({
workspace,
domain,
- domainChecks,
+ dubDomainChecks,
}: {
workspace: WorkspaceWithUsers;
domain: string;
- domainChecks?: boolean; // if the action needs to check if the domain belongs to the workspace
+ dubDomainChecks?: boolean; // if we also need to make sure the user can actually make changes to dub default domains
}) => {
const domainRecord = await prisma.domain.findUnique({
where: { slug: domain },
@@ -24,22 +24,22 @@ export const getDomainOrThrow = async ({
}
// if domain is defined:
- // - it's a dub domain and domainChecks is required, check if the user is part of the dub workspace
+ // - it's a dub domain and dubDomainChecks is required, check if the user is part of the dub workspace
// - it's a custom domain, check if the domain belongs to the workspace
- if (isDubDomain(domain)) {
- if (domainChecks && workspace.id !== DUB_WORKSPACE_ID) {
- throw new DubApiError({
- code: "forbidden",
- message: `Domain ${domain} does not belong to workspace ws_${workspace.id}.`,
- });
- }
- } else {
- if (domainRecord.projectId !== workspace.id) {
- throw new DubApiError({
- code: "forbidden",
- message: `Domain ${domain} does not belong to workspace ws_${workspace.id}.`,
- });
- }
+ if (
+ isDubDomain(domain) &&
+ dubDomainChecks &&
+ workspace.id !== DUB_WORKSPACE_ID
+ ) {
+ throw new DubApiError({
+ code: "forbidden",
+ message: `Domain ${domain} does not belong to workspace ws_${workspace.id}.`,
+ });
+ } else if (domainRecord.projectId !== workspace.id) {
+ throw new DubApiError({
+ code: "forbidden",
+ message: `Domain ${domain} does not belong to workspace ws_${workspace.id}.`,
+ });
}
return domainRecord;