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.

fix scope array

Kiran K6bfafabd7dcf
diff --git a/apps/web/app/api/tokens/[id]/route.ts b/apps/web/app/api/tokens/[id]/route.ts
index 8210918382..3b9d02ac47 100644
--- a/apps/web/app/api/tokens/[id]/route.ts
+++ b/apps/web/app/api/tokens/[id]/route.ts
@@ -59,8 +59,8 @@ export const PATCH = withWorkspace(
projectId: workspace.id,
},
data: {
- name,
- scopes: scopes.join(" "),
+ ...(name && { name }),
+ ...(scopes && { scopes: [...new Set(scopes)].join(" ") }),
},
select: {
id: true,
diff --git a/apps/web/app/api/tokens/route.ts b/apps/web/app/api/tokens/route.ts
index 46fd2cda2c..2f02c4308e 100644
--- a/apps/web/app/api/tokens/route.ts
+++ b/apps/web/app/api/tokens/route.ts
@@ -50,7 +50,8 @@ export const POST = withWorkspace(
partialKey,
userId: isMachine ? machineUser?.id! : session.user.id,
projectId: workspace.id,
- scopes: scopes && scopes.length > 0 ? scopes.join(" ") : null,
+ scopes:
+ scopes && scopes.length > 0 ? [...new Set(scopes)].join(" ") : null,
},
});
diff --git a/apps/web/lib/api/tokens/permissions.ts b/apps/web/lib/api/tokens/permissions.ts
index ce8daa2e7d..836a74dd93 100644
--- a/apps/web/lib/api/tokens/permissions.ts
+++ b/apps/web/lib/api/tokens/permissions.ts
@@ -16,8 +16,6 @@ export const throwIfNoAccess = ({
return;
}
- console.log("Checking scopes", scopes, requiredScopes);
-
for (const requiredScope of requiredScopes) {
if (scopes.includes(requiredScope)) {
return;
diff --git a/apps/web/lib/zod/schemas/token.ts b/apps/web/lib/zod/schemas/token.ts
index 592e98de10..f2bf826a0f 100644
--- a/apps/web/lib/zod/schemas/token.ts
+++ b/apps/web/lib/zod/schemas/token.ts
@@ -10,7 +10,7 @@ export const createTokenSchema = z.object({
.min(1)
.max(50),
isMachine: z.boolean().optional().default(false),
- scopes: z.array(z.enum(availableScopes)).optional(),
+ scopes: z.array(z.enum(availableScopes)).default([]).optional(),
});
// Schema to validate the request body when updating a token