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.

Update workspace-related strings

Kiran K7f45ae32dc25
diff --git a/apps/web/app/api/auth/saml/verify/route.tsx b/apps/web/app/api/auth/saml/verify/route.tsx
index 19016227b1..360fcb312c 100644
--- a/apps/web/app/api/auth/saml/verify/route.tsx
+++ b/apps/web/app/api/auth/saml/verify/route.tsx
@@ -9,7 +9,7 @@ export async function POST(req: Request) {
if (!slug) {
return NextResponse.json(
- { error: "No project slug provided." },
+ { error: "No workspace slug provided." },
{ status: 400 },
);
}
@@ -20,7 +20,10 @@ export async function POST(req: Request) {
});
if (!project) {
- return NextResponse.json({ error: "Project not found." }, { status: 404 });
+ return NextResponse.json(
+ { error: "Workspace not found." },
+ { status: 404 },
+ );
}
const connections = await apiController.getConnections({
@@ -30,7 +33,7 @@ export async function POST(req: Request) {
if (!connections || connections.length === 0) {
return NextResponse.json(
- { error: "No SSO connections found for this project." },
+ { error: "No SSO connections found for this workspace." },
{ status: 404 },
);
}
diff --git a/apps/web/app/api/projects/[slug]/(old)/route.ts b/apps/web/app/api/projects/[slug]/(old)/route.ts
new file mode 100644
index 0000000000..91aab13957
--- /dev/null
+++ b/apps/web/app/api/projects/[slug]/(old)/route.ts
@@ -0,0 +1 @@
+export * from "../../../workspaces/[workspaceId]/route";
diff --git a/apps/web/app/api/projects/route.ts b/apps/web/app/api/projects/route.ts
index aade5170ee..b9398941b3 100644
--- a/apps/web/app/api/projects/route.ts
+++ b/apps/web/app/api/projects/route.ts
@@ -1,158 +1 @@
-import {
- addDomainToVercel,
- domainExists,
- setRootDomain,
-} from "@/lib/api/domains";
-import { DubApiError } from "@/lib/api/errors";
-import { withSession } from "@/lib/auth";
-import { isReservedKey } from "@/lib/edge-config";
-import prisma from "@/lib/prisma";
-import z from "@/lib/zod";
-import {
- DEFAULT_REDIRECTS,
- FREE_PROJECTS_LIMIT,
- nanoid,
- validDomainRegex,
- validSlugRegex,
-} from "@dub/utils";
-import slugify from "@sindresorhus/slugify";
-import { NextResponse } from "next/server";
-
-const createProjectSchema = z.object({
- name: z.string().min(1).max(32),
- slug: z
- .string()
- .min(3, "Slug must be at least 3 characters")
- .max(48, "Slug must be less than 48 characters")
- .transform((v) => slugify(v))
- .refine((v) => validSlugRegex.test(v), { message: "Invalid slug format" })
- .refine(async (v) => !((await isReservedKey(v)) || DEFAULT_REDIRECTS[v]), {
- message: "Cannot use reserved slugs",
- }),
- domain: z
- .string()
- .refine((v) => validDomainRegex.test(v), {
- message: "Invalid domain format",
- })
- .optional(),
-});
-
-// GET /api/projects - get all projects for the current user
-export const GET = withSession(async ({ session }) => {
- const projects = await prisma.project.findMany({
- where: {
- users: {
- some: {
- userId: session.user.id,
- },
- },
- },
- include: {
- domains: true,
- users: {
- where: {
- userId: session.user.id,
- },
- select: {
- role: true,
- },
- },
- },
- });
- return NextResponse.json(projects);
-});
-
-export const POST = withSession(async ({ req, session }) => {
- const { name, slug, domain } = await createProjectSchema.parseAsync(
- await req.json(),
- );
-
- const freeProjects = await prisma.project.count({
- where: {
- plan: "free",
- users: {
- some: {
- userId: session.user.id,
- role: "owner",
- },
- },
- },
- });
-
- if (freeProjects >= FREE_PROJECTS_LIMIT) {
- throw new DubApiError({
- code: "exceeded_limit",
- message: `You can only create up to ${FREE_PROJECTS_LIMIT} free projects. Additional projects require a paid plan.`,
- });
- }
-
- const [slugExist, domainExist] = await Promise.all([
- prisma.project.findUnique({
- where: {
- slug,
- },
- select: {
- slug: true,
- },
- }),
- domain ? domainExists(domain) : false,
- ]);
-
- if (slugExist) {
- throw new DubApiError({
- code: "conflict",
- message: "Slug is already in use.",
- });
- }
-
- if (domainExist) {
- throw new DubApiError({
- code: "conflict",
- message: "Domain is already in use.",
- });
- }
-
- const [projectResponse, domainRepsonse] = await Promise.all([
- prisma.project.create({
- data: {
- name,
- slug,
- users: {
- create: {
- userId: session.user.id,
- role: "owner",
- },
- },
- ...(domain && {
- domains: {
- create: {
- slug: domain,
- primary: true,
- },
- },
- }),
- billingCycleStart: new Date().getDate(),
- inviteCode: nanoid(24),
- defaultDomains: {
- create: {}, // by default, we give users all the default domains when they create a project
- },
- },
- include: {
- domains: true,
- },
- }),
- domain && addDomainToVercel(domain),
- ]);
-
- // if domain is specified and it was successfully added to Vercel
- // update it in Redis cache
- if (domain && domainRepsonse && !domainRepsonse.error) {
- await setRootDomain({
- id: projectResponse.domains[0].id,
- domain,
- projectId: projectResponse.id,
- });
- }
-
- return NextResponse.json(projectResponse);
-});
+export * from "../workspaces/route";
diff --git a/apps/web/app/api/projects/[slug]/route.ts b/apps/web/app/api/workspaces/[workspaceId]/route.ts
similarity index 97%
rename from apps/web/app/api/projects/[slug]/route.ts
rename to apps/web/app/api/workspaces/[workspaceId]/route.ts
index f950438f09..b3da56cf37 100644
--- a/apps/web/app/api/projects/[slug]/route.ts
+++ b/apps/web/app/api/workspaces/[workspaceId]/route.ts
@@ -49,7 +49,7 @@ export const PUT = withAuth(
if (error.code === "P2002") {
throw new DubApiError({
code: "conflict",
- message: "Project slug already exists.",
+ message: "Workspace slug already exists.",
});
}
diff --git a/apps/web/app/api/workspaces/route.ts b/apps/web/app/api/workspaces/route.ts
new file mode 100644
index 0000000000..0c4c62dba1
--- /dev/null
+++ b/apps/web/app/api/workspaces/route.ts
@@ -0,0 +1,158 @@
+import {
+ addDomainToVercel,
+ domainExists,
+ setRootDomain,
+} from "@/lib/api/domains";
+import { DubApiError } from "@/lib/api/errors";
+import { withSession } from "@/lib/auth";
+import { isReservedKey } from "@/lib/edge-config";
+import prisma from "@/lib/prisma";
+import z from "@/lib/zod";
+import {
+ DEFAULT_REDIRECTS,
+ FREE_PROJECTS_LIMIT,
+ nanoid,
+ validDomainRegex,
+ validSlugRegex,
+} from "@dub/utils";
+import slugify from "@sindresorhus/slugify";
+import { NextResponse } from "next/server";
+
+const createProjectSchema = z.object({
+ name: z.string().min(1).max(32),
+ slug: z
+ .string()
+ .min(3, "Slug must be at least 3 characters")
+ .max(48, "Slug must be less than 48 characters")
+ .transform((v) => slugify(v))
+ .refine((v) => validSlugRegex.test(v), { message: "Invalid slug format" })
+ .refine(async (v) => !((await isReservedKey(v)) || DEFAULT_REDIRECTS[v]), {
+ message: "Cannot use reserved slugs",
+ }),
+ domain: z
+ .string()
+ .refine((v) => validDomainRegex.test(v), {
+ message: "Invalid domain format",
+ })
+ .optional(),
+});
+
+// GET /api/projects - get all projects for the current user
+export const GET = withSession(async ({ session }) => {
+ const projects = await prisma.project.findMany({
+ where: {
+ users: {
+ some: {
+ userId: session.user.id,
+ },
+ },
+ },
+ include: {
+ domains: true,
+ users: {
+ where: {
+ userId: session.user.id,
+ },
+ select: {
+ role: true,
+ },
+ },
+ },
+ });
+ return NextResponse.json(projects);
+});
+
+export const POST = withSession(async ({ req, session }) => {
+ const { name, slug, domain } = await createProjectSchema.parseAsync(
+ await req.json(),
+ );
+
+ const freeProjects = await prisma.project.count({
+ where: {
+ plan: "free",
+ users: {
+ some: {
+ userId: session.user.id,
+ role: "owner",
+ },
+ },
+ },
+ });
+
+ if (freeProjects >= FREE_PROJECTS_LIMIT) {
+ throw new DubApiError({
+ code: "exceeded_limit",
+ message: `You can only create up to ${FREE_PROJECTS_LIMIT} free workspaces. Additional workspaces require a paid plan.`,
+ });
+ }
+
+ const [slugExist, domainExist] = await Promise.all([
+ prisma.project.findUnique({
+ where: {
+ slug,
+ },
+ select: {
+ slug: true,
+ },
+ }),
+ domain ? domainExists(domain) : false,
+ ]);
+
+ if (slugExist) {
+ throw new DubApiError({
+ code: "conflict",
+ message: "Slug is already in use.",
+ });
+ }
+
+ if (domainExist) {
+ throw new DubApiError({
+ code: "conflict",
+ message: "Domain is already in use.",
+ });
+ }
+
+ const [projectResponse, domainRepsonse] = await Promise.all([
+ prisma.project.create({
+ data: {
+ name,
+ slug,
+ users: {
+ create: {
+ userId: session.user.id,
+ role: "owner",
+ },
+ },
+ ...(domain && {
+ domains: {
+ create: {
+ slug: domain,
+ primary: true,
+ },
+ },
+ }),
+ billingCycleStart: new Date().getDate(),
+ inviteCode: nanoid(24),
+ defaultDomains: {
+ create: {}, // by default, we give users all the default domains when they create a project
+ },
+ },
+ include: {
+ domains: true,
+ },
+ }),
+ domain && addDomainToVercel(domain),
+ ]);
+
+ // if domain is specified and it was successfully added to Vercel
+ // update it in Redis cache
+ if (domain && domainRepsonse && !domainRepsonse.error) {
+ await setRootDomain({
+ id: projectResponse.domains[0].id,
+ domain,
+ projectId: projectResponse.id,
+ });
+ }
+
+ return NextResponse.json(projectResponse);
+});
diff --git a/apps/web/lib/api/users.ts b/apps/web/lib/api/users.ts
index 34a1926483..97cea587db 100644
--- a/apps/web/lib/api/users.ts
+++ b/apps/web/lib/api/users.ts
@@ -35,7 +35,7 @@ export async function inviteUser({
if (error.code === "P2002") {
throw new DubApiError({
code: "conflict",
- message: "User has already been invited to this project.",
+ message: "User has already been invited to this workspace.",
});
}
}
diff --git a/apps/web/lib/auth/index.ts b/apps/web/lib/auth/index.ts
index 2935252e41..bc538f4e27 100644
--- a/apps/web/lib/auth/index.ts
+++ b/apps/web/lib/auth/index.ts
@@ -119,8 +119,8 @@ export const withAuth = (
let headers = {};
const slug = params?.slug || searchParams.projectSlug;
- const workspaceId = searchParams?.workspaceId;
-
+ const workspaceId = params?.workspaceId || searchParams.workspaceId;
+ console.log({ params, searchParams });
try {
// if there's no projectSlug defined
if (!slug) {
@@ -280,7 +280,7 @@ export const withAuth = (
// project doesn't exist
throw new DubApiError({
code: "not_found",
- message: "Project not found.",
+ message: "Workspace not found.",
});
}
@@ -292,7 +292,7 @@ export const withAuth = (
) {
throw new DubApiError({
code: "forbidden",
- message: "Domain does not belong to project.",
+ message: "Domain does not belong to workspace.",
});
}
@@ -312,17 +312,17 @@ export const withAuth = (
if (!pendingInvites) {
throw new DubApiError({
code: "not_found",
- message: "Project not found.",
+ message: "Workspace not found.",
});
} else if (pendingInvites.expires < new Date()) {
throw new DubApiError({
code: "invite_expired",
- message: "Project invite expired.",
+ message: "Workspace invite expired.",
});
} else {
throw new DubApiError({
code: "invite_pending",
- message: "Project invite pending.",
+ message: "Workspace invite pending.",
});
}
}
@@ -427,7 +427,6 @@ export const withAuth = (
link,
});
} catch (error) {
- console.error("withAuth Error -->", error.message);
return handleAndReturnErrorResponse(error);
}
};