Skip to content

Commit 91b2284

Browse files
committed
Prioritize JWT over service API keys in authentication
1 parent a3a4bf4 commit 91b2284

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

.changeset/shaky-eels-shine.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+
Prioritize JWT over service API keys in authentication

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,17 @@ export async function fetchTeamAndProject(
258258
method: "GET",
259259
headers: {
260260
...(authData.secretKey ? { "x-secret-key": authData.secretKey } : {}),
261-
...(authData.jwt ? { Authorization: `Bearer ${authData.jwt}` } : {}),
262-
// use the incoming service api key if it exists, otherwise use the service api key
263-
// this is done to ensure that the incoming service API key is VALID in the first place
264-
"x-service-api-key": incomingServiceApiKey
265-
? incomingServiceApiKey
266-
: serviceApiKey,
261+
...(authData.jwt
262+
? { Authorization: `Bearer ${authData.jwt}` }
263+
: // if the JWT is not present ww'll use service api keys, if there is a JWT present we'll always use the JWT
264+
{
265+
// use the incoming service api key if it exists, otherwise use the service api key
266+
// this is done to ensure that the incoming service API key is VALID in the first place
267+
"x-service-api-key": incomingServiceApiKey
268+
? incomingServiceApiKey
269+
: serviceApiKey,
270+
}),
271+
267272
"content-type": "application/json",
268273
},
269274
});

0 commit comments

Comments
 (0)