Skip to content

Commit 1fa36c1

Browse files
authored
chore: allow passing teamId to service-utils auth (#6329)
1 parent fa99acf commit 1fa36c1

File tree

6 files changed

+19
-3
lines changed

6 files changed

+19
-3
lines changed

.changeset/cuddly-plants-wait.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/service-utils": patch
3+
---
4+
5+
chore: Allow passing teamId with dashboard auth

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export async function extractAuthorizationData(
157157
origin,
158158
bundleId,
159159
secretKeyHash,
160+
teamId: authInput.teamId,
160161
targetAddress: authInput.targetAddress,
161162
};
162163
}

packages/service-utils/src/core/api.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,15 @@ export async function fetchTeamAndProject(
158158
config: CoreServiceConfig,
159159
): Promise<ApiResponse> {
160160
const { apiUrl, serviceApiKey } = config;
161+
const { teamId, clientId } = authData;
161162

162-
const clientId = authData.clientId;
163-
const url = `${apiUrl}/v2/keys/use${clientId ? `?clientId=${clientId}` : ""}`;
163+
const url = new URL("/v2/keys/use", apiUrl);
164+
if (clientId) {
165+
url.searchParams.set("clientId", clientId);
166+
}
167+
if (teamId) {
168+
url.searchParams.set("teamId", teamId);
169+
}
164170
const response = await fetch(url, {
165171
method: "GET",
166172
headers: {

packages/service-utils/src/core/authorize/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type AuthorizationInput = {
1818
jwt: string | null;
1919
hashedJWT: string | null;
2020
targetAddress?: string | string[];
21+
teamId?: string;
2122
// IMPORTANT: this is a stringified boolean! Only pass in true or false here. IK it's not ideal, but it's required to pass it in the headers.
2223
useWalletAuth?: string | null;
2324
};
@@ -46,7 +47,7 @@ export async function authorize(
4647
const cacheKey = authData.secretKeyHash
4748
? `key-v2:secret-key:${authData.secretKeyHash}`
4849
: authData.hashedJWT
49-
? `key-v2:dashboard-jwt:${authData.hashedJWT}`
50+
? `key-v2:dashboard-jwt:${authData.hashedJWT}:${authData.teamId ?? "default"}`
5051
: authData.clientId
5152
? `key-v2:client-id:${authData.clientId}`
5253
: null;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export type CoreAuthInput = {
22
// for passing it from the subdomain or path or other service specific things
33
clientId?: string;
4+
// For providing a specific team the user is trying to authenticate for. Used only for dashboard auth.
5+
teamId?: string;
46
// for passing in the address target in RPC or bundler services
57
targetAddress?: string | string[];
68
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export function extractAuthorizationData(
167167
origin,
168168
bundleId,
169169
targetAddress: authInput.targetAddress,
170+
teamId: authInput.teamId,
170171
useWalletAuth,
171172
};
172173
}

0 commit comments

Comments
 (0)