Skip to content

Commit 9d72ddd

Browse files
authored
Allow passing team ID explicitly via request headers (#6771)
1 parent 17b8368 commit 9d72ddd

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

.changeset/giant-moons-sleep.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@thirdweb-dev/service-utils": patch
3+
"thirdweb": patch
4+
---
5+
6+
allow passing the team id explicitly via request headers

packages/service-utils/src/cf-worker/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ export async function extractAuthorizationData(
156156
}
157157
}
158158

159+
let teamId: string | null = null;
160+
if (headers.has("x-team-id")) {
161+
teamId = headers.get("x-team-id");
162+
}
163+
159164
return {
160165
incomingServiceApiKey,
161166
incomingServiceApiKeyHash,
@@ -168,7 +173,7 @@ export async function extractAuthorizationData(
168173
origin,
169174
bundleId,
170175
secretKeyHash,
171-
teamId: authInput.teamId,
176+
teamId: authInput.teamId ?? teamId ?? undefined,
172177
targetAddress: authInput.targetAddress,
173178
};
174179
}

packages/service-utils/src/node/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ export function extractAuthorizationData(
160160
}
161161
}
162162

163+
let teamId: string | null = null;
164+
if (getHeader(headers, "x-team-id")) {
165+
teamId = getHeader(headers, "x-team-id");
166+
}
167+
163168
return {
164169
incomingServiceApiKey,
165170
incomingServiceApiKeyHash,
@@ -173,7 +178,7 @@ export function extractAuthorizationData(
173178
origin,
174179
bundleId,
175180
targetAddress: authInput.targetAddress,
176-
teamId: authInput.teamId,
181+
teamId: authInput.teamId ?? teamId ?? undefined,
177182
useWalletAuth,
178183
};
179184
}

packages/thirdweb/src/client/client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ type ClientOptions = Prettify<{
4949
gatewayUrl?: string;
5050
};
5151
};
52+
53+
/**
54+
* The team ID for thirdweb dashboard usage.
55+
* @hidden
56+
*/
57+
teamId?: string;
5258
}>;
5359

5460
export type CreateThirdwebClientOptions = Prettify<

packages/thirdweb/src/utils/fetch.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export function getClientFetch(client: ThirdwebClient, ecosystem?: Ecosystem) {
5555
!isBundlerUrl(urlString)
5656
) {
5757
headers.set("authorization", `Bearer ${authToken}`);
58+
// if we have a specific teamId set, add it to the request headers
59+
if (client.teamId) {
60+
headers.set("x-team-id", client.teamId);
61+
}
5862
} else if (secretKey) {
5963
headers.set("x-secret-key", secretKey);
6064
} else if (clientId) {

0 commit comments

Comments
 (0)