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.

domain checks

Kiran K3ad15e8f9eba
diff --git a/apps/web/app/api/analytics/events/export/route.ts b/apps/web/app/api/analytics/events/export/route.ts
index a05c343714..6eccf65995 100644
--- a/apps/web/app/api/analytics/events/export/route.ts
+++ b/apps/web/app/api/analytics/events/export/route.ts
@@ -1,6 +1,7 @@
import { getEvents } from "@/lib/analytics/get-events";
import { convertToCSV, validDateRangeForPlan } from "@/lib/analytics/utils";
-import { getLink } from "@/lib/api/links/get-link";
+import { getDomainOrThrow } from "@/lib/api/domains/get-domain";
+import { getLinkOrThrow } from "@/lib/api/links/get-link";
import { withWorkspace } from "@/lib/auth";
import { eventsQuerySchema } from "@/lib/zod/schemas/analytics";
import { clickEventEnrichedSchema } from "@/lib/zod/schemas/clicks";
@@ -51,8 +52,12 @@ export const GET = withWorkspace(
const { event, domain, interval, start, end, columns, key } = parsedParams;
+ if (domain) {
+ await getDomainOrThrow({ workspace, domain });
+ }
+
const link =
- domain && key ? await getLink({ workspace, domain, key }) : null;
+ domain && key ? await getLinkOrThrow({ workspace, domain, key }) : null;
validDateRangeForPlan({
plan: workspace.plan,
diff --git a/apps/web/app/api/analytics/events/route.ts b/apps/web/app/api/analytics/events/route.ts
index ed87acfab3..3f5e42d215 100644
--- a/apps/web/app/api/analytics/events/route.ts
+++ b/apps/web/app/api/analytics/events/route.ts
@@ -1,6 +1,7 @@
import { getEvents } from "@/lib/analytics/get-events";
import { validDateRangeForPlan } from "@/lib/analytics/utils";
-import { getLink } from "@/lib/api/links/get-link";
+import { getDomainOrThrow } from "@/lib/api/domains/get-domain";
+import { getLinkOrThrow } from "@/lib/api/links/get-link";
import { withWorkspace } from "@/lib/auth";
import { eventsQuerySchema } from "@/lib/zod/schemas/analytics";
import { Link } from "@prisma/client";
@@ -14,8 +15,12 @@ export const GET = withWorkspace(
parsedParams;
let link: Link | null = null;
+ if (domain) {
+ await getDomainOrThrow({ workspace, domain });
+ }
+
if (linkId || externalId || (domain && key)) {
- link = await getLink({
+ link = await getLinkOrThrow({
workspace: workspace,
linkId,
externalId,
diff --git a/apps/web/app/api/analytics/export/route.ts b/apps/web/app/api/analytics/export/route.ts
index 217003af99..35e26baaff 100644
--- a/apps/web/app/api/analytics/export/route.ts
+++ b/apps/web/app/api/analytics/export/route.ts
@@ -1,7 +1,8 @@
import { VALID_ANALYTICS_ENDPOINTS } from "@/lib/analytics/constants";
import { getAnalytics } from "@/lib/analytics/get-analytics";
import { convertToCSV, validDateRangeForPlan } from "@/lib/analytics/utils";
-import { getLink } from "@/lib/api/links/get-link";
+import { getDomainOrThrow } from "@/lib/api/domains/get-domain";
+import { getLinkOrThrow } from "@/lib/api/links/get-link";
import { withWorkspace } from "@/lib/auth";
import { analyticsQuerySchema } from "@/lib/zod/schemas/analytics";
import JSZip from "jszip";
@@ -13,8 +14,12 @@ export const GET = withWorkspace(
const { interval, start, end, linkId, domain, key } = parsedParams;
+ if (domain) {
+ await getDomainOrThrow({ workspace, domain });
+ }
+
const link =
- domain && key ? await getLink({ workspace, domain, key }) : null;
+ domain && key ? await getLinkOrThrow({ workspace, domain, key }) : null;
validDateRangeForPlan({
plan: workspace.plan,
diff --git a/apps/web/app/api/analytics/public-stats/route.ts b/apps/web/app/api/analytics/public-stats/route.ts
index 35078d2317..ced4260c08 100644
--- a/apps/web/app/api/analytics/public-stats/route.ts
+++ b/apps/web/app/api/analytics/public-stats/route.ts
@@ -1,3 +1,4 @@
+import { getDomainOrThrow } from "@/lib/api/domains/get-domain";
import { withWorkspace } from "@/lib/auth";
import { getLinkViaEdge } from "@/lib/planetscale";
import { prisma } from "@/lib/prisma";
@@ -10,17 +11,22 @@ const updatePublicStatsSchema = z.object({
});
// GET /api/analytics/public-stats – get the publicStats setting for a link
-export const GET = withWorkspace(async ({ searchParams }) => {
+export const GET = withWorkspace(async ({ searchParams, workspace }) => {
const { domain, key } = domainKeySchema.parse(searchParams);
+
+ await getDomainOrThrow({ domain, workspace });
+
const response = await getLinkViaEdge(domain, key);
return NextResponse.json({ publicStats: response?.publicStats });
});
// PUT /api/analytics/public-stats – update the publicStats setting for a link
-export const PUT = withWorkspace(async ({ req, searchParams }) => {
+export const PUT = withWorkspace(async ({ req, searchParams, workspace }) => {
const { domain, key } = domainKeySchema.parse(searchParams);
const { publicStats } = updatePublicStatsSchema.parse(await req.json());
+ await getDomainOrThrow({ domain, workspace });
+
const response = await prisma.link.update({
where: { domain_key: { domain, key } },
data: { publicStats },
diff --git a/apps/web/app/api/analytics/route.ts b/apps/web/app/api/analytics/route.ts
index 4fe4bdcf86..9365738633 100644
--- a/apps/web/app/api/analytics/route.ts
+++ b/apps/web/app/api/analytics/route.ts
@@ -1,7 +1,8 @@
import { VALID_ANALYTICS_ENDPOINTS } from "@/lib/analytics/constants";
import { getAnalytics } from "@/lib/analytics/get-analytics";
import { validDateRangeForPlan } from "@/lib/analytics/utils";
-import { getLink } from "@/lib/api/links/get-link";
+import { getDomainOrThrow } from "@/lib/api/domains/get-domain";
+import { getLinkOrThrow } from "@/lib/api/links/get-link";
import { withWorkspace } from "@/lib/auth";
import {
analyticsPathParamsSchema,
@@ -37,8 +38,12 @@ export const GET = withWorkspace(
} = parsedParams;
let link: Link | null = null;
+ if (domain) {
+ await getDomainOrThrow({ workspace, domain });
+ }
+
if (linkId || externalId || (domain && key)) {
- link = await getLink({
+ link = await getLinkOrThrow({
workspace: workspace,
linkId,
externalId,
diff --git a/apps/web/app/api/domains/[domain]/primary/route.ts b/apps/web/app/api/domains/[domain]/primary/route.ts
index d30dbc3a68..697c1ac763 100644
--- a/apps/web/app/api/domains/[domain]/primary/route.ts
+++ b/apps/web/app/api/domains/[domain]/primary/route.ts
@@ -1,3 +1,4 @@
+import { getDomainOrThrow } from "@/lib/api/domains/get-domain";
import { withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { DomainSchema } from "@/lib/zod/schemas/domains";
@@ -6,7 +7,11 @@ import { NextResponse } from "next/server";
// POST /api/domains/[domain]/primary – set a domain as primary
export const POST = withWorkspace(
async ({ headers, workspace, params }) => {
- const { domain } = params;
+ const { slug: domain } = await getDomainOrThrow({
+ domain: params.domain,
+ workspace,
+ domainChecks: true,
+ });
const [domainRecord] = await Promise.all([
prisma.domain.update({
@@ -36,7 +41,6 @@ export const POST = withWorkspace(
return NextResponse.json(DomainSchema.parse(domainRecord), { headers });
},
{
- domainChecks: true,
requiredRole: ["owner"],
},
);
diff --git a/apps/web/app/api/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.ts
index ad9dcba54b..c2e72ab6a5 100644
--- a/apps/web/app/api/domains/[domain]/route.ts
+++ b/apps/web/app/api/domains/[domain]/route.ts
@@ -4,6 +4,7 @@ import {
removeDomainFromVercel,
validateDomain,
} from "@/lib/api/domains";
+import { getDomainOrThrow } from "@/lib/api/domains/get-domain";
import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
@@ -18,35 +19,24 @@ import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
// GET /api/domains/[domain] – get a workspace's domain
-export const GET = withWorkspace(
- async ({ workspace, params }) => {
- const { domain } = params;
-
- const domainRecord = await prisma.domain.findUnique({
- where: {
- slug: domain,
- projectId: workspace.id,
- },
- });
-
- if (!domainRecord) {
- throw new DubApiError({
- code: "not_found",
- message: "Domain not found",
- });
- }
-
- return NextResponse.json(DomainSchema.parse(domainRecord));
- },
- {
+export const GET = withWorkspace(async ({ workspace, params }) => {
+ const domainRecord = await getDomainOrThrow({
+ domain: params.domain,
+ workspace,
domainChecks: true,
- },
-);
+ });
+
+ return NextResponse.json(DomainSchema.parse(domainRecord));
+});
// PUT /api/domains/[domain] – edit a workspace's domain
export const PATCH = withWorkspace(
async ({ req, workspace, params }) => {
- const { domain } = params;
+ const { slug: domain } = await getDomainOrThrow({
+ domain: params.domain,
+ workspace,
+ domainChecks: true,
+ });
const {
slug: newDomain,
@@ -135,22 +125,24 @@ export const PATCH = withWorkspace(
return NextResponse.json(DomainSchema.parse(domainRecord));
},
{
- domainChecks: true,
requiredRole: ["owner"],
},
);
// DELETE /api/domains/[domain] - delete a workspace's domain
export const DELETE = withWorkspace(
- async ({ params }) => {
- const { domain } = params;
+ async ({ params, workspace }) => {
+ const { slug: domain } = await getDomainOrThrow({
+ domain: params.domain,
+ workspace,
+ domainChecks: true,
+ });
await deleteDomainAndLinks(domain);
return NextResponse.json({ slug: domain });
},
{
- domainChecks: true,
requiredRole: ["owner"],
},
);
diff --git a/apps/web/app/api/domains/[domain]/transfer/route.ts b/apps/web/app/api/domains/[domain]/transfer/route.ts
index bef71ec552..decb6e0789 100644
--- a/apps/web/app/api/domains/[domain]/transfer/route.ts
+++ b/apps/web/app/api/domains/[domain]/transfer/route.ts
@@ -1,4 +1,5 @@
import { getAnalytics } from "@/lib/analytics/get-analytics";
+import { getDomainOrThrow } from "@/lib/api/domains/get-domain";
import { DubApiError } from "@/lib/api/errors";
import { withWorkspace } from "@/lib/auth";
import { qstash } from "@/lib/cron";
@@ -13,7 +14,12 @@ import { NextResponse } from "next/server";
// POST /api/domains/[domain]/transfer – transfer a domain to another workspace
export const POST = withWorkspace(
async ({ req, headers, session, params, workspace }) => {
- const { domain } = params;
+ const { slug: domain } = await getDomainOrThrow({
+ domain: params.domain,
+ workspace,
+ domainChecks: true,
+ });
+
const { newWorkspaceId } = transferDomainBodySchema.parse(await req.json());
if (newWorkspaceId === workspace.id) {
@@ -133,7 +139,6 @@ export const POST = withWorkspace(
return NextResponse.json(DomainSchema.parse(domainResponse), { headers });
},
{
- domainChecks: true,
requiredRole: ["owner"],
},
);
diff --git a/apps/web/app/api/domains/[domain]/verify/route.ts b/apps/web/app/api/domains/[domain]/verify/route.ts
index 5dbcbe33e9..2553ad11df 100644
--- a/apps/web/app/api/domains/[domain]/verify/route.ts
+++ b/apps/web/app/api/domains/[domain]/verify/route.ts
@@ -3,6 +3,7 @@ import {
getDomainResponse,
verifyDomain,
} from "@/lib/api/domains";
+import { getDomainOrThrow } from "@/lib/api/domains/get-domain";
import { withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { DomainVerificationStatusProps } from "@/lib/types";
@@ -11,8 +12,11 @@ import { NextResponse } from "next/server";
export const maxDuration = 30;
// GET /api/domains/[domain]/verify - get domain verification status
-export const GET = withWorkspace(async ({ params }) => {
- const { domain } = params;
+export const GET = withWorkspace(async ({ params, workspace }) => {
+ const { slug: domain } = await getDomainOrThrow({
+ domain: params.domain,
+ workspace,
+ });
let status: DomainVerificationStatusProps = "Valid Configuration";
diff --git a/apps/web/app/api/domains/route.ts b/apps/web/app/api/domains/route.ts
index 9feff4987b..eba4a36bd3 100644
--- a/apps/web/app/api/domains/route.ts
+++ b/apps/web/app/api/domains/route.ts
@@ -26,7 +26,13 @@ export const POST = withWorkspace(async ({ req, workspace }) => {
const body = await parseRequestBody(req);
const { slug, placeholder, expiredUrl } = createDomainBodySchema.parse(body);
- if (workspace.domains.length >= workspace.domainsLimit) {
+ const totalDomains = await prisma.domain.count({
+ where: {
+ projectId: workspace.id,
+ },
+ });
+
+ if (totalDomains >= workspace.domainsLimit) {
return new Response(
exceededLimitError({
plan: workspace.plan,
@@ -67,7 +73,7 @@ export const POST = withWorkspace(async ({ req, workspace }) => {
data: {
slug: slug,
projectId: workspace.id,
- primary: workspace.domains.length === 0,
+ primary: totalDomains === 0,
...(placeholder && { placeholder }),
...(workspace.plan !== "free" && {
expiredUrl,
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.ts
index 2699d8806c..27734a7140 100644
--- a/apps/web/app/api/links/[linkId]/route.ts
+++ b/apps/web/app/api/links/[linkId]/route.ts
@@ -1,3 +1,4 @@
+import { getDomainOrThrow } from "@/lib/api/domains/get-domain";
import { DubApiError, ErrorCodes } from "@/lib/api/errors";
import {
deleteLink,
@@ -5,7 +6,7 @@ import {
transformLink,
updateLink,
} from "@/lib/api/links";
-import { getLink } from "@/lib/api/links/get-link";
+import { getLinkOrThrow } from "@/lib/api/links/get-link";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
@@ -16,7 +17,7 @@ import { NextResponse } from "next/server";
// GET /api/links/[linkId] – get a link
export const GET = withWorkspace(async ({ headers, workspace, params }) => {
- const link = await getLink({
+ const link = await getLinkOrThrow({
workspace,
linkId: params.linkId,
});
@@ -49,13 +50,17 @@ export const GET = withWorkspace(async ({ headers, workspace, params }) => {
// PATCH /api/links/[linkId] – update a link
export const PATCH = withWorkspace(
async ({ req, headers, workspace, params }) => {
- const link = await getLink({
+ const link = await getLinkOrThrow({
workspace,
linkId: params.linkId,
});
const body = updateLinkBodySchema.parse(await parseRequestBody(req));
+ if (body?.domain) {
+ await getDomainOrThrow({ domain: body.domain, workspace });
+ }
+
// Add body onto existing link but maintain NewLinkProps form for processLink
const updatedLink = {
...link,
@@ -137,7 +142,7 @@ export const PUT = PATCH;
// DELETE /api/links/[linkId] – delete a link
export const DELETE = withWorkspace(async ({ headers, workspace, params }) => {
- const link = await getLink({
+ const link = await getLinkOrThrow({
workspace,
linkId: params.linkId,
});
diff --git a/apps/web/app/api/links/[linkId]/transfer/route.ts b/apps/web/app/api/links/[linkId]/transfer/route.ts
index 490919b561..96036dc3ee 100644
--- a/apps/web/app/api/links/[linkId]/transfer/route.ts
+++ b/apps/web/app/api/links/[linkId]/transfer/route.ts
@@ -1,6 +1,6 @@
import { getAnalytics } from "@/lib/analytics/get-analytics";
import { DubApiError } from "@/lib/api/errors";
-import { getLink } from "@/lib/api/links/get-link";
+import { getLinkOrThrow } from "@/lib/api/links/get-link";
import { withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { recordLink } from "@/lib/tinybird";
@@ -20,7 +20,7 @@ const transferLinkBodySchema = z.object({
// POST /api/links/[linkId]/transfer – transfer a link to another workspace
export const POST = withWorkspace(
async ({ req, headers, session, params, workspace }) => {
- const link = await getLink({
+ const link = await getLinkOrThrow({
workspace,
linkId: params.linkId,
});
diff --git a/apps/web/app/api/links/count/route.ts b/apps/web/app/api/links/count/route.ts
index 8c3bd12894..ee14c36f21 100644
--- a/apps/web/app/api/links/count/route.ts
+++ b/apps/web/app/api/links/count/route.ts
@@ -1,3 +1,4 @@
+import { getDomainOrThrow } from "@/lib/api/domains/get-domain";
import { getLinksCount } from "@/lib/api/links";
import { withWorkspace } from "@/lib/auth";
import { getLinksCountQuerySchema } from "@/lib/zod/schemas/links";
@@ -6,7 +7,12 @@ import { NextResponse } from "next/server";
// GET /api/links/count – get the number of links for a workspace
export const GET = withWorkspace(
async ({ headers, searchParams, workspace }) => {
- const { userId, ...params } = getLinksCountQuerySchema.parse(searchParams);
+ const params = getLinksCountQuerySchema.parse(searchParams);
+ const { userId, domain } = params;
+
+ if (domain) {
+ await getDomainOrThrow({ domain, workspace: workspace });
+ }
const count = await getLinksCount({
searchParams: params,
diff --git a/apps/web/app/api/links/info/route.ts b/apps/web/app/api/links/info/route.ts
index bc1b39fc88..33b13353f1 100644
--- a/apps/web/app/api/links/info/route.ts
+++ b/apps/web/app/api/links/info/route.ts
@@ -1,6 +1,6 @@
import { DubApiError } from "@/lib/api/errors";
import { transformLink } from "@/lib/api/links";
-import { getLink } from "@/lib/api/links/get-link";
+import { getLinkOrThrow } from "@/lib/api/links/get-link";
import { withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { getLinkInfoQuerySchema } from "@/lib/zod/schemas/links";
@@ -21,7 +21,7 @@ export const GET = withWorkspace(
});
}
- const link = await getLink({
+ const link = await getLinkOrThrow({
workspace,
linkId,
externalId,
diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.ts
index bf9170221c..da41afa426 100644
--- a/apps/web/app/api/links/route.ts
+++ b/apps/web/app/api/links/route.ts
@@ -1,3 +1,4 @@
+import { getDomainOrThrow } from "@/lib/api/domains/get-domain";
import { DubApiError, ErrorCodes } from "@/lib/api/errors";
import { createLink, getLinksForWorkspace, processLink } from "@/lib/api/links";
import { parseRequestBody } from "@/lib/api/utils";
@@ -27,6 +28,10 @@ export const GET = withWorkspace(async ({ req, headers, workspace }) => {
includeUser,
} = getLinksQuerySchemaExtended.parse(searchParams);
+ if (domain) {
+ await getDomainOrThrow({ domain, workspace });
+ }
+
const response = await getLinksForWorkspace({
workspaceId: workspace.id,
domain,
diff --git a/apps/web/lib/api/domains/get-domain.ts b/apps/web/lib/api/domains/get-domain.ts
new file mode 100644
index 0000000000..673a2c61e7
--- /dev/null
+++ b/apps/web/lib/api/domains/get-domain.ts
@@ -0,0 +1,46 @@
+import { prisma } from "@/lib/prisma";
+import { WorkspaceWithUsers } from "@/lib/types";
+import { DUB_WORKSPACE_ID, isDubDomain } from "@dub/utils";
+import { DubApiError } from "../errors";
+
+export const getDomainOrThrow = async ({
+ domain,
+ workspace,
+ domainChecks,
+}: {
+ domain: string;
+ workspace: WorkspaceWithUsers;
+ domainChecks?: boolean; // if the action needs to check if the domain belongs to the workspace
+}) => {
+ const domainRecord = await prisma.domain.findUnique({
+ where: { slug: domain },
+ });
+
+ if (!domainRecord) {
+ throw new DubApiError({
+ code: "not_found",
+ message: `Domain ${domain} not found.`,
+ });
+ }
+
+ // 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 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}.`,
+ });
+ }
+ }
+
+ return domainRecord;
+};
diff --git a/apps/web/lib/api/links/get-link.ts b/apps/web/lib/api/links/get-link.ts
index fece7108dd..5f15c42fc7 100644
--- a/apps/web/lib/api/links/get-link.ts
+++ b/apps/web/lib/api/links/get-link.ts
@@ -1,10 +1,10 @@
import { prisma } from "@/lib/prisma";
-import { WorkspaceProps } from "@/lib/types";
+import { WorkspaceWithUsers } from "@/lib/types";
import { Link } from "@prisma/client";
import { DubApiError } from "../errors";
interface GetLinkParams {
- workspace: WorkspaceProps;
+ workspace: WorkspaceWithUsers;
linkId?: string;
externalId?: string;
domain?: string;
@@ -12,7 +12,7 @@ interface GetLinkParams {
}
// Find link
-export const getLink = async (params: GetLinkParams) => {
+export const getLinkOrThrow = async (params: GetLinkParams) => {
let { workspace, domain, key, externalId } = params;
let link: Link | null = null;
diff --git a/apps/web/lib/auth/workspace.ts b/apps/web/lib/auth/workspace.ts
index 002f0c691b..6a120a67b4 100644
--- a/apps/web/lib/auth/workspace.ts
+++ b/apps/web/lib/auth/workspace.ts
@@ -4,14 +4,9 @@ import {
handleAndReturnErrorResponse,
} from "@/lib/api/errors";
import { prisma } from "@/lib/prisma";
-import { PlanProps, WorkspaceProps } from "@/lib/types";
+import { PlanProps, WorkspaceWithUsers } from "@/lib/types";
import { ratelimit } from "@/lib/upstash";
-import {
- API_DOMAIN,
- DUB_WORKSPACE_ID,
- getSearchParams,
- isDubDomain,
-} from "@dub/utils";
+import { API_DOMAIN, getSearchParams } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { isBetaTester } from "../edge-config";
import { hashToken } from "./hash-token";
@@ -31,7 +26,7 @@ interface WithWorkspaceHandler {
searchParams: Record<string, string>;
headers?: Record<string, string>;
session: Session;
- workspace: WorkspaceProps;
+ workspace: WorkspaceWithUsers;
}): Promise<Response>;
}
@@ -52,7 +47,6 @@ export const withWorkspace = (
needNotExceededLinks, // if the action needs the user to not have exceeded their links usage
allowAnonymous, // special case for /api/links (POST /api/links) – allow no session
allowSelf, // special case for removing yourself from a workspace
- domainChecks, // if the action needs to check if the domain belongs to the workspace
betaFeature, // if the action is a beta feature
}: {
requiredPlan?: Array<PlanProps>;
@@ -61,7 +55,6 @@ export const withWorkspace = (
needNotExceededLinks?: boolean;
allowAnonymous?: boolean;
allowSelf?: boolean;
- domainChecks?: boolean;
betaFeature?: boolean;
} = {},
) => {
@@ -87,7 +80,6 @@ export const withWorkspace = (
apiKey = authorizationHeader.replace("Bearer ", "");
}
- const domain = params?.domain || searchParams.domain;
let session: Session | undefined;
let workspaceId: string | undefined;
let workspaceSlug: string | undefined;
@@ -210,15 +202,8 @@ export const withWorkspace = (
role: true,
},
},
- domains: {
- select: {
- id: true,
- slug: true,
- primary: true,
- },
- },
},
- })) as WorkspaceProps;
+ })) as WorkspaceWithUsers;
// workspace doesn't exist
if (!workspace || !workspace.users) {
@@ -239,25 +224,6 @@ export const withWorkspace = (
}
}
- // 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 custom domain, check if the domain belongs to the workspace
- if (domain) {
- if (isDubDomain(domain)) {
- if (domainChecks && workspace.id !== DUB_WORKSPACE_ID) {
- throw new DubApiError({
- code: "forbidden",
- message: "Domain does not belong to workspace.",
- });
- }
- } else if (!workspace.domains.find((d) => d.slug === domain)) {
- throw new DubApiError({
- code: "forbidden",
- message: "Domain does not belong to workspace.",
- });
- }
- }
-
// workspace exists but user is not part of it
if (workspace.users.length === 0) {
const pendingInvites = await prisma.projectInvite.findUnique({
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 800ac64eff..4708aa3666 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -98,6 +98,8 @@ export interface WorkspaceProps {
betaTester?: boolean;
}
+export type WorkspaceWithUsers = Omit<WorkspaceProps, "domains">;
+
export interface UserProps {
id: string;
name: string;