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.

add createWorkspaceId

Kiran K9de42ff34779
diff --git a/apps/web/app/api/workspaces/route.ts b/apps/web/app/api/workspaces/route.ts
index 7ddeb1e34c..3c7253d101 100644
--- a/apps/web/app/api/workspaces/route.ts
+++ b/apps/web/app/api/workspaces/route.ts
@@ -1,6 +1,8 @@
-import { createId } from "@/lib/api/create-id";
import { DubApiError } from "@/lib/api/errors";
-import { transformWorkspaceId } from "@/lib/api/workspace-id";
+import {
+ createWorkspaceId,
+ transformWorkspaceId,
+} from "@/lib/api/workspace-id";
import { withSession } from "@/lib/auth";
import { checkIfUserExists } from "@/lib/planetscale";
import {
@@ -94,7 +96,7 @@ export const POST = withSession(async ({ req, session }) => {
try {
const workspaceResponse = await prisma.project.create({
data: {
- id: createId({ prefix: "ws_" }),
+ id: createWorkspaceId(),
name,
slug,
users: {
diff --git a/apps/web/lib/api/workspace-id.ts b/apps/web/lib/api/workspace-id.ts
index 11d0b3e48b..919a3d6a79 100644
--- a/apps/web/lib/api/workspace-id.ts
+++ b/apps/web/lib/api/workspace-id.ts
@@ -1,3 +1,5 @@
+import { createId } from "./create-id";
+
export const transformWorkspaceId = (workspaceId: string) => {
return workspaceId.startsWith("ws_") ? workspaceId : `ws_${workspaceId}`;
};
@@ -7,3 +9,13 @@ export const getWorkspaceId = (workspaceId: string) => {
? workspaceId.replace("ws_", "")
: workspaceId;
};
+
+export const createWorkspaceId = () => {
+ const workspaceId = createId({ prefix: "ws_" });
+
+ if (workspaceId.startsWith("ws_c")) {
+ return createWorkspaceId();
+ }
+
+ return workspaceId;
+};