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.

simplify

Kiran Kd3182f3772c0
diff --git a/apps/web/lib/api/tokens/permissions.ts b/apps/web/lib/api/tokens/permissions.ts
index 34b680d815..d9f312a2d3 100644
--- a/apps/web/lib/api/tokens/permissions.ts
+++ b/apps/web/lib/api/tokens/permissions.ts
@@ -1,6 +1,8 @@
import { DubApiError } from "../errors";
import { Scope } from "./scopes";
+// Check if the required scope is in the list of scopes
+// If not, throw an error immediately with a message
export const throwIfNoAccess = ({
scopes,
requiredScopes,
@@ -8,9 +10,11 @@ export const throwIfNoAccess = ({
scopes: Scope[];
requiredScopes: Scope[];
}) => {
+ if (requiredScopes.length === 0) {
+ return;
+ }
+
for (const requiredScope of requiredScopes) {
- // Check if the required scope is in the list of scopes
- // If not, throw an error immediately with a message
if (!scopes.includes(requiredScope)) {
throw new DubApiError({
code: "forbidden",
diff --git a/apps/web/lib/auth/workspace.ts b/apps/web/lib/auth/workspace.ts
index e836b178b2..845734973a 100644
--- a/apps/web/lib/auth/workspace.ts
+++ b/apps/web/lib/auth/workspace.ts
@@ -299,9 +299,7 @@ export const withWorkspace = (
}
// Check user has permission to make the action
- if (requiredScopes.length > 0) {
- throwIfNoAccess({ scopes, requiredScopes });
- }
+ throwIfNoAccess({ scopes, requiredScopes });
// beta feature checks
if (betaFeature) {