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.

Merge branch 'main' into kiran/eng-281-restricted-api-keys

Kiran K445d9d6ff687
diff --cc apps/web/lib/auth/workspace.ts
index 29d57a8a82,e61aeed7d1..f0f7747111
--- a/apps/web/lib/auth/workspace.ts
+++ b/apps/web/lib/auth/workspace.ts
@@@ -12,14 -12,9 +12,15 @@@ import
getSearchParams,
isDubDomain,
} from "@dub/utils";
-import { Link as LinkProps } from "@prisma/client";
+import {
+ Link as LinkProps,
+ RestrictedToken,
+ Token,
+ User,
+} from "@prisma/client";
import { waitUntil } from "@vercel/functions";
+import { Scope, scopes as allScopes, roleToScopes } from "../api/tokens/scopes";
+ import { isBetaTester } from "../edge-config";
import { hashToken } from "./hash-token";
import { Session, getSession } from "./utils";
@@@ -287,11 -268,17 +290,22 @@@ export const withWorkspace =
});
}
+ // beta feature checks
+ if (betaFeature) {
+ const betaTester = await isBetaTester(workspace.id);
+ if (!betaTester) {
+ throw new DubApiError({
+ code: "forbidden",
+ message: "Unauthorized: Beta feature.",
+ });
+ }
+ }
+
+ // For session requests, find the scopes based on the user's role
+ if (!apiKey) {
+ scopes = roleToScopes[workspace.users[0].role];
+ }
+
// edge case where linkId is an externalId and workspaceId was not provided (they must've used projectSlug instead)
// in this case, we need to try fetching the link again
if (linkId && linkId.startsWith("ext_") && !link && !workspaceId) {