-
Notifications
You must be signed in to change notification settings - Fork 621
[SDK] Fix SIWE auth forcing unnecessary chain switch #7104
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] Fix SIWE auth forcing unnecessary chain switch #7104
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe update modifies the SIWE authentication flow in the "thirdweb" component by refining the logic that determines whether a chain switch is necessary. Now, the chain switch is only triggered if the payload's chain ID exists and is different from the active wallet's current chain ID, preventing redundant chain switching. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ConnectButton
participant useSiweAuth
participant Wallet
User->>ConnectButton: Initiate SIWE authentication
ConnectButton->>useSiweAuth: Begin authentication
useSiweAuth->>Wallet: Get current chain ID
useSiweAuth->>useSiweAuth: Check payload.chainId vs Wallet.chainId
alt chainId exists and differs
useSiweAuth->>Wallet: Switch chain
end
useSiweAuth->>Wallet: Proceed with authentication
Assessment against linked issues
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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. |
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
🧹 Nitpick comments (1)
packages/thirdweb/src/react/core/hooks/auth/useSiweAuth.ts (1)
100-100: Consider adding a type check for payload.chain_id.While the fix works correctly, consider adding an explicit check using
typeof payload.chain_id !== 'undefined'instead of relying on truthiness, which might fail for chain ID 0 (if that's ever a valid chain ID).-if (payload.chain_id && Number(payload.chain_id) !== chain.id) { +if (typeof payload.chain_id !== 'undefined' && Number(payload.chain_id) !== chain.id) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.changeset/ten-parrots-poke.md(1 hunks)packages/thirdweb/src/react/core/hooks/auth/useSiweAuth.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: Unit Tests
- GitHub Check: E2E Tests (pnpm, webpack)
- GitHub Check: Size
- GitHub Check: Lint Packages
- GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
.changeset/ten-parrots-poke.md (1)
1-6: Changeset description is clear and accurately describes the fix.The changeset correctly identifies the issue being fixed (unnecessary chain switching during SIWE auth) and provides a concise explanation. This is appropriate for a patch-level change.
packages/thirdweb/src/react/core/hooks/auth/useSiweAuth.ts (1)
100-104: Fix looks good - prevents unnecessary chain switching.The conditional now properly checks both for the existence of
payload.chain_idand whether it differs from the current chain's ID before initiating a chain switch. This addresses the original issue of forcing unnecessary chain switches during SIWE authentication.Before this change, a chain switch would be triggered whenever
payload.chain_idexisted, even if the user was already on the correct chain.
size-limit report 📦
|
Codecov ReportAttention: Patch coverage is
❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #7104 +/- ##
=======================================
Coverage 55.59% 55.59%
=======================================
Files 901 901
Lines 58121 58121
Branches 4064 4064
=======================================
Hits 32313 32313
Misses 25703 25703
Partials 105 105
🚀 New features to boost your workflow:
|

Fixes TOOL-4554
PR-Codex overview
This PR focuses on fixing an issue in the
useSiweAuthhook related to the authentication process by ensuring that a chain switch is only triggered when thechain_idin the payload is different from the current chain.Detailed summary
useSiweAuth.tsto check ifpayload.chain_idis both present and different from the currentchain.idbefore callingactiveWallet.switchChain.Summary by CodeRabbit