Skip to content

Separate authToken from secretKey in ThirdwebClient #6983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

jnsdls
Copy link
Member

@jnsdls jnsdls commented May 8, 2025

PR-Codex overview

This PR focuses on refactoring the createThirdwebClient function to replace the use of secretKey with authToken, enhancing how authentication is managed and improving error handling related to client creation.

Detailed summary

  • Replaced secretKey with authToken in createThirdwebClient options.
  • Updated tests to reflect changes in authentication method.
  • Added error handling for cases where clientId must accompany authToken.
  • Modified type definitions to include authToken.
  • Adjusted fetch logic to prioritize authToken over secretKey.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

vercel bot commented May 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2025 11:10pm
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2025 11:10pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2025 11:10pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2025 11:10pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2025 11:10pm

Copy link

changeset-bot bot commented May 8, 2025

⚠️ No Changeset found

Latest commit: f2b9861

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added Dashboard Involves changes to the Dashboard. packages SDK Involves changes to the thirdweb SDK labels May 8, 2025
Copy link
Member Author

jnsdls commented May 8, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jnsdls jnsdls marked this pull request as ready for review May 8, 2025 22:54
@jnsdls jnsdls requested review from a team as code owners May 8, 2025 22:54
Comment on lines 44 to +57
if (!headers) {
headers = new Headers();
}
// auth token if secret key === jwt
const authToken =
useAuthToken && client.secretKey && isJWT(client.secretKey)
? client.secretKey
: undefined;
// secret key if secret key !== jwt
const secretKey =
client.secretKey && !isJWT(client.secretKey)
? client.secretKey
: undefined;
const clientId = client.clientId;

// if we have an auth token set, use that (thirdweb dashboard sets this for the user)

// if we have an auth token set & useAuthToken is true, use the auth token (thirdweb dashboard sets this for the user)
// pay urls should never send the auth token, because we always want the "developer" to be the one making the request, not the "end user"
if (
authToken &&
useAuthToken &&
client.authToken &&
!isPayUrl(urlString) &&
!isInAppWalletUrl(urlString) &&
!isBundlerUrl(urlString)
) {
headers.set("authorization", `Bearer ${authToken}`);
headers.set("authorization", `Bearer ${client.authToken}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code should be modified to maintain backward compatibility with tests that expect JWT tokens to be passed as secretKey. We should check both client.authToken and if client.secretKey is a JWT. For example: if (useAuthToken && (client.authToken || (client.secretKey && isJWT(client.secretKey))) && ...)

Spotted by Diamond (based on CI logs)

Is this helpful? React 👍 or 👎 to let us know.

Copy link
Contributor

github-actions bot commented May 8, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 54.16 KB (-0.03% 🔽) 1.1 s (-0.03% 🔽) 188 ms (+164.21% 🔺) 1.3 s
thirdweb (cjs) 193.94 KB (+0.03% 🔺) 3.9 s (+0.03% 🔺) 371 ms (+36.31% 🔺) 4.3 s
thirdweb (minimal + tree-shaking) 5.68 KB (-0.06% 🔽) 114 ms (-0.06% 🔽) 85 ms (+1985.98% 🔺) 198 ms
thirdweb/chains (tree-shaking) 524 B (0%) 11 ms (0%) 40 ms (+2417.8% 🔺) 50 ms
thirdweb/react (minimal + tree-shaking) 19.47 KB (-0.17% 🔽) 390 ms (-0.17% 🔽) 73 ms (+536.4% 🔺) 462 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dashboard Involves changes to the Dashboard. packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant