-
Notifications
You must be signed in to change notification settings - Fork 620
[SDK] Update useAuthToken to find auth token for any connected wallet #8402
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
[SDK] Update useAuthToken to find auth token for any connected wallet #8402
Conversation
🦋 Changeset detectedLatest commit: 6a26251 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. |
WalkthroughA new changeset documents a patch update for the "thirdweb" package. The Changes
Sequence Diagram(s)sequenceDiagram
participant Component
participant useAuthToken as useAuthToken()
participant Helper as useWalletWithAuthToken
participant Wallets as Connected Wallets
rect rgb(230, 240, 250)
Note over Component,Wallets: New Implementation
end
Component->>useAuthToken: get auth token
useAuthToken->>Helper: find wallet with auth token
Helper->>Wallets: iterate through all connected wallets
Wallets-->>Helper: check for getAuthToken method
alt Token found
Helper-->>useAuthToken: first wallet with auth token
useAuthToken->>Wallets: retrieve auth token
Wallets-->>useAuthToken: auth token
useAuthToken-->>Component: return token
else No token found
Helper-->>useAuthToken: null
useAuthToken-->>Component: return null
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10-15 minutes
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts (1)
7-30: Update JSDoc to reflect the new wallet selection behavior.The documentation still references "the currently active wallet" and "the active wallet" (lines 8, 11), but the implementation now searches all connected wallets and returns the token from the first wallet that has one, regardless of which wallet is active.
Apply this diff to update the documentation:
/** - * A hook that returns the authentication token (JWT) for the currently active wallet. + * A hook that returns the authentication token (JWT) from any connected wallet that supports authentication. * This token can be used to authorize API calls to your backend server. * - * @returns The JWT string if the active wallet is an in-app wallet and matches the active account, null otherwise + * @returns The JWT string from the first connected wallet (InAppWallet or EcosystemWallet) that has an auth token, or null if no connected wallet has one * * @example
🧹 Nitpick comments (2)
packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts (2)
31-39: Consider documenting the wallet selection order.The implementation returns the auth token from the first connected wallet that has one. If multiple wallets are connected and have auth tokens, the order of
useConnectedWallets()determines which token is returned. This behavior should be documented in the JSDoc or a code comment.
47-47: Simplify redundant undefined coalescing.The expression
wallet ?? undefinedis redundant sincewalletis already typed asInAppWallet | EcosystemWallet | undefinedfrom thefind()result.Apply this diff:
- return wallet ?? undefined; + return wallet;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
.changeset/clean-tools-learn.md(1 hunks)packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from@/typesor localtypes.tsbarrels
Prefer type aliases over interface except for nominal shapes
Avoidanyandunknownunless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial,Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose
Files:
packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)
Files:
packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts
🧠 Learnings (11)
📓 Common learnings
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Support for in-app wallets (social/email login)
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Unified `Wallet` and `Account` interfaces in wallet architecture
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Smart wallets with account abstraction
📚 Learning: 2025-07-18T19:19:55.613Z
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : EIP-1193, EIP-5792, EIP-7702 standard support in wallet modules
Applied to files:
.changeset/clean-tools-learn.mdpackages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts
📚 Learning: 2025-07-18T19:19:55.613Z
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Smart wallets with account abstraction
Applied to files:
.changeset/clean-tools-learn.mdpackages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts
📚 Learning: 2025-07-18T19:19:55.613Z
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Support for in-app wallets (social/email login)
Applied to files:
.changeset/clean-tools-learn.mdpackages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts
📚 Learning: 2025-07-18T19:19:55.613Z
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to packages/thirdweb/src/wallets/** : Unified `Wallet` and `Account` interfaces in wallet architecture
Applied to files:
.changeset/clean-tools-learn.mdpackages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/**/api/**/*.{ts,tsx} : Always call `getAuthToken()` to get the JWT from cookies.
Applied to files:
packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts
📚 Learning: 2025-07-18T19:19:55.613Z
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to apps/{dashboard,playground-web}/**/*.{ts,tsx} : Always call `getAuthToken()` to retrieve JWT from cookies on server side
Applied to files:
packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/**/*client.tsx : Interactive UI that relies on hooks (`useState`, `useEffect`, React Query, wallet hooks).
Applied to files:
packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts
📚 Learning: 2025-07-18T19:19:55.613Z
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-07-18T19:19:55.613Z
Learning: Applies to test/src/test-wallets.ts : Predefined test accounts are in `test/src/test-wallets.ts`
Applied to files:
packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/**/*client.tsx : Create light wrappers (e.g. `fetchJson`) that automatically attach the JWT from cookies/session when calling internal API routes.
Applied to files:
packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts
📚 Learning: 2025-07-18T19:20:32.530Z
Learnt from: CR
Repo: thirdweb-dev/js PR: 0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-18T19:20:32.530Z
Learning: Applies to dashboard/**/*.{ts,tsx} : Reading cookies/headers with `next/headers` (`getAuthToken()`, `cookies()`).
Applied to files:
packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts
🧬 Code graph analysis (1)
packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts (1)
packages/thirdweb/src/wallets/in-app/core/wallet/types.ts (1)
InAppWallet(21-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: Lint Packages
- GitHub Check: E2E Tests (pnpm, vite)
- GitHub Check: E2E Tests (pnpm, esbuild)
- GitHub Check: E2E Tests (pnpm, webpack)
- GitHub Check: Size
- GitHub Check: Build Packages
- GitHub Check: Unit Tests
- GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
.changeset/clean-tools-learn.md (1)
1-5: LGTM! Changeset documentation is clear and accurate.The changeset correctly documents a patch update with a clear description of the behavioral change in
useAuthToken().packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts (2)
1-5: LGTM! Imports are appropriate for the updated implementation.The new type imports (
InAppWallet,EcosystemWallet) anduseConnectedWalletshook are correctly imported and align with the new wallet-scanning approach.
41-48: Type assertion verified as safe.The verification confirms that only
InAppWalletandEcosystemWalletexpose thegetAuthTokenmethod. The type casting inuseWalletWithAuthTokenis correct and safe.The code functions properly. Minor code quality note: the
wallet ?? undefinedon line 47 is redundant sincewalletis already typed asInAppWallet | EcosystemWallet | undefined, so it could simplify toreturn wallet.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8402 +/- ##
=======================================
Coverage 54.82% 54.82%
=======================================
Files 919 919
Lines 60840 60840
Branches 4140 4135 -5
=======================================
Hits 33356 33356
- Misses 27382 27383 +1
+ Partials 102 101 -1
🚀 New features to boost your workflow:
|
size-limit report 📦
|

PR-Codex overview
This PR updates the
useAuthToken()hook to retrieve the authentication token from any connected wallet instead of only the active one, enhancing flexibility in wallet management.Detailed summary
useActiveWallet()anduseActiveAccount()imports.useConnectedWallets()to access all connected wallets.useAuthToken()to return the auth token from any wallet with an auth token.useWalletWithAuthToken()function to find a wallet with an auth token.Summary by CodeRabbit
Bug Fixes