diff --git a/.changeset/giant-moons-sleep.md b/.changeset/giant-moons-sleep.md new file mode 100644 index 00000000000..1ed681c8fad --- /dev/null +++ b/.changeset/giant-moons-sleep.md @@ -0,0 +1,6 @@ +--- +"@thirdweb-dev/service-utils": patch +"thirdweb": patch +--- + +allow passing the team id explicitly via request headers diff --git a/packages/service-utils/src/cf-worker/index.ts b/packages/service-utils/src/cf-worker/index.ts index e5bca55728c..9c835528915 100644 --- a/packages/service-utils/src/cf-worker/index.ts +++ b/packages/service-utils/src/cf-worker/index.ts @@ -156,6 +156,11 @@ export async function extractAuthorizationData( } } + let teamId: string | null = null; + if (headers.has("x-team-id")) { + teamId = headers.get("x-team-id"); + } + return { incomingServiceApiKey, incomingServiceApiKeyHash, @@ -168,7 +173,7 @@ export async function extractAuthorizationData( origin, bundleId, secretKeyHash, - teamId: authInput.teamId, + teamId: authInput.teamId ?? teamId ?? undefined, targetAddress: authInput.targetAddress, }; } diff --git a/packages/service-utils/src/node/index.ts b/packages/service-utils/src/node/index.ts index edb1695b098..66618952f85 100644 --- a/packages/service-utils/src/node/index.ts +++ b/packages/service-utils/src/node/index.ts @@ -160,6 +160,11 @@ export function extractAuthorizationData( } } + let teamId: string | null = null; + if (getHeader(headers, "x-team-id")) { + teamId = getHeader(headers, "x-team-id"); + } + return { incomingServiceApiKey, incomingServiceApiKeyHash, @@ -173,7 +178,7 @@ export function extractAuthorizationData( origin, bundleId, targetAddress: authInput.targetAddress, - teamId: authInput.teamId, + teamId: authInput.teamId ?? teamId ?? undefined, useWalletAuth, }; } diff --git a/packages/thirdweb/src/client/client.ts b/packages/thirdweb/src/client/client.ts index a804210b8ed..4c10e25f30f 100644 --- a/packages/thirdweb/src/client/client.ts +++ b/packages/thirdweb/src/client/client.ts @@ -49,6 +49,12 @@ type ClientOptions = Prettify<{ gatewayUrl?: string; }; }; + + /** + * The team ID for thirdweb dashboard usage. + * @hidden + */ + teamId?: string; }>; export type CreateThirdwebClientOptions = Prettify< diff --git a/packages/thirdweb/src/utils/fetch.ts b/packages/thirdweb/src/utils/fetch.ts index b7f71452ce5..a52b104d9ad 100644 --- a/packages/thirdweb/src/utils/fetch.ts +++ b/packages/thirdweb/src/utils/fetch.ts @@ -55,6 +55,10 @@ export function getClientFetch(client: ThirdwebClient, ecosystem?: Ecosystem) { !isBundlerUrl(urlString) ) { headers.set("authorization", `Bearer ${authToken}`); + // if we have a specific teamId set, add it to the request headers + if (client.teamId) { + headers.set("x-team-id", client.teamId); + } } else if (secretKey) { headers.set("x-secret-key", secretKey); } else if (clientId) {