Skip to content

Conversation

@joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Nov 12, 2025


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

  • Removed useActiveWallet() and useActiveAccount() imports.
  • Introduced useConnectedWallets() to access all connected wallets.
  • Modified useAuthToken() to return the auth token from any wallet with an auth token.
  • Added useWalletWithAuthToken() function to find a wallet with an auth token.

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

Summary by CodeRabbit

Bug Fixes

  • Fixed authentication token retrieval to search across all connected wallets instead of only the currently active wallet, improving token availability and reliability.

@changeset-bot
Copy link

changeset-bot bot commented Nov 12, 2025

🦋 Changeset detected

Latest commit: 6a26251

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
thirdweb Patch
@thirdweb-dev/nebula Patch
@thirdweb-dev/wagmi-adapter Patch
wagmi-inapp Patch

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

@vercel
Copy link

vercel bot commented Nov 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
docs-v2 Ready Ready Preview Comment Nov 12, 2025 7:08pm
nebula Ready Ready Preview Comment Nov 12, 2025 7:08pm
thirdweb_playground Ready Ready Preview Comment Nov 12, 2025 7:08pm
thirdweb-www Ready Ready Preview Comment Nov 12, 2025 7:08pm
wallet-ui Ready Ready Preview Comment Nov 12, 2025 7:08pm

@joaquim-verges joaquim-verges marked this pull request as ready for review November 12, 2025 18:56
@joaquim-verges joaquim-verges requested review from a team as code owners November 12, 2025 18:56
@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Nov 12, 2025
Copy link
Member Author

joaquim-verges commented Nov 12, 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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 12, 2025

Walkthrough

A new changeset documents a patch update for the "thirdweb" package. The useAuthToken() hook is modified to search all connected wallets for an authentication token, rather than retrieving it from only the active wallet. The public API signature remains unchanged, but the internal wallet selection and token retrieval logic is updated.

Changes

Cohort / File(s) Summary
Changeset Documentation
.changeset/clean-tools-learn.md
New changeset file documenting a patch-level update describing the behavioral change to useAuthToken().
Authentication Token Hook
packages/thirdweb/src/react/core/hooks/wallets/useAuthToken.ts
Replaces active wallet-based token retrieval with logic that scans all connected wallets. Introduces internal useWalletWithAuthToken helper to locate the first connected wallet exposing a getAuthToken method. Updates imports to include InAppWallet, EcosystemWallet, and useConnectedWallets; removes useActiveAccount and useActiveWallet dependencies.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10-15 minutes

  • Changes are localized to a single hook implementation and a new changeset file
  • The behavioral change follows a straightforward pattern: iterate connected wallets instead of checking active wallet
  • Public API remains backward compatible (same function signature)
  • Primary focus areas:
    • Verify the wallet iteration logic correctly handles all wallet types supporting getAuthToken
    • Ensure the helper function properly returns the first matching wallet or null
    • Confirm removal of old dependencies does not break related functionality
    • Validate that the change maintains expected behavior for existing consumers

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete. While an auto-generated PR-Codex summary is present, the required template sections (issue tag, reviewer notes, testing details) are unfilled or commented out. Fill in the required sections: add the Linear issue tag (TEAM-0000 format), provide notes for reviewers, and specify how to test the changes (unit tests, playground examples).
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: updating useAuthToken to find the auth token for any connected wallet rather than just the active one.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch _SDK_Update_useAuthToken_to_find_auth_token_for_any_connected_wallet

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 ?? undefined is redundant since wallet is already typed as InAppWallet | EcosystemWallet | undefined from the find() 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.

📥 Commits

Reviewing files that changed from the base of the PR and between be3316e and 6a26251.

📒 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 @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless 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.md
  • 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 packages/thirdweb/src/wallets/** : Smart wallets with account abstraction

Applied to files:

  • .changeset/clean-tools-learn.md
  • 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 packages/thirdweb/src/wallets/** : Support for in-app wallets (social/email login)

Applied to files:

  • .changeset/clean-tools-learn.md
  • 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 packages/thirdweb/src/wallets/** : Unified `Wallet` and `Account` interfaces in wallet architecture

Applied to files:

  • .changeset/clean-tools-learn.md
  • 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/**/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) and useConnectedWallets hook are correctly imported and align with the new wallet-scanning approach.


41-48: Type assertion verified as safe.

The verification confirms that only InAppWallet and EcosystemWallet expose the getAuthToken method. The type casting in useWalletWithAuthToken is correct and safe.

The code functions properly. Minor code quality note: the wallet ?? undefined on line 47 is redundant since wallet is already typed as InAppWallet | EcosystemWallet | undefined, so it could simplify to return wallet.

@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.82%. Comparing base (be3316e) to head (6a26251).
⚠️ Report is 1 commits behind head on main.

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     
Flag Coverage Δ
packages 54.82% <ø> (ø)
see 1 file with indirect coverage changes
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 12, 2025

size-limit report 📦

Path Size
@thirdweb-dev/nexus (esm) 104.88 KB (0%)
@thirdweb-dev/nexus (cjs) 316.6 KB (0%)

@joaquim-verges joaquim-verges merged commit e26d81c into main Nov 12, 2025
25 of 26 checks passed
@joaquim-verges joaquim-verges deleted the _SDK_Update_useAuthToken_to_find_auth_token_for_any_connected_wallet branch November 12, 2025 19:06
@joaquim-verges joaquim-verges mentioned this pull request Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages SDK Involves changes to the thirdweb SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants