From bf8e4cde3dfaf8d40cb2a8bd1d9d4bdaf93ee91b Mon Sep 17 00:00:00 2001 From: Kelechi Date: Tue, 5 May 2026 13:58:18 +0100 Subject: [PATCH 1/3] fix: resolve Web3Auth social login failure caused by unreliable viem default RPCs Replace viem's default RPC endpoints (eth.merkle.io, polygon-rpc.com) with reliable PublicNode RPCs for Ethereum and Polygon. These defaults fail for eth_getBlockByNumber which Web3Auth's TransactionFormatter calls during provider setup after OAuth, causing social login to silently fail. Also fixes blockExplorerUrl bug where string indexing returned a single character instead of the full URL, and passes chainConfig to the Web3Auth constructor as required by the SDK. --- .changeset/fix-web3auth-social-login.md | 11 +++++++++++ src/config/iq-login.config.ts | 19 ++++++++++++++++--- src/hooks/use-web-3-auth.tsx | 6 ++++-- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 .changeset/fix-web3auth-social-login.md diff --git a/.changeset/fix-web3auth-social-login.md b/.changeset/fix-web3auth-social-login.md new file mode 100644 index 0000000..f9a38f3 --- /dev/null +++ b/.changeset/fix-web3auth-social-login.md @@ -0,0 +1,11 @@ +--- +"@everipedia/iq-login": patch +--- + +Fix Web3Auth social login by replacing unreliable viem default RPCs with PublicNode RPCs + +Viem's default RPCs (eth.merkle.io, polygon-rpc.com) fail for the RPC methods Web3Auth +calls during provider setup after OAuth, causing social login to silently fail and return +to the modal. This replaces them with reliable PublicNode RPCs for known chains and fixes +the blockExplorerUrl bug where string indexing returned a single character instead of the +full URL. diff --git a/src/config/iq-login.config.ts b/src/config/iq-login.config.ts index 0824e7e..1813430 100644 --- a/src/config/iq-login.config.ts +++ b/src/config/iq-login.config.ts @@ -35,6 +35,16 @@ export interface IqLoginConfig { chains: [Chain, ...Chain[]]; } +// Reliable public RPCs for Web3Auth's provider setup. +// Viem's default RPCs can be unreliable for eth_getBlockByNumber which +// Web3Auth's TransactionFormatter.getEIP1559Compatibility calls during +// provider setup after OAuth. e.g. eth.merkle.io times out on this call, +// polygon-rpc.com returns no result. PublicNode handles these reliably. +export const WEB3AUTH_RPC_TARGETS: Record = { + 1: "https://ethereum-rpc.publicnode.com", // Ethereum Mainnet + 137: "https://polygon-bor-rpc.publicnode.com", // Polygon +}; + export function createIqLoginConfig( chains: [Chain, ...Chain[]] = [mainnet], ): IqLoginConfig { @@ -85,16 +95,19 @@ function createWeb3AuthInstance(defaultChain: Chain) { const chainConfig = { chainNamespace: Web3AuthBase.CHAIN_NAMESPACES.EIP155, chainId: `0x${defaultChain.id.toString(16)}`, - rpcTarget: defaultChain.rpcUrls.default.http[0], + rpcTarget: + WEB3AUTH_RPC_TARGETS[defaultChain.id] ?? + defaultChain.rpcUrls.default.http[0], displayName: defaultChain.name, tickerName: defaultChain.nativeCurrency?.name, ticker: defaultChain.nativeCurrency?.symbol, - blockExplorerUrl: defaultChain.blockExplorers?.default.url[0] as string, + blockExplorerUrl: defaultChain.blockExplorers?.default.url as string, }; - // Initialize Web3Auth with only the default chain + // Initialize Web3Auth with the default chain return new Web3AuthModal.Web3Auth({ clientId: WEB_3_AUTH_CLIENT_ID, + chainConfig, privateKeyProvider: new Web3AuthEthereumProvider.EthereumPrivateKeyProvider( { config: { chainConfig }, diff --git a/src/hooks/use-web-3-auth.tsx b/src/hooks/use-web-3-auth.tsx index 50142d2..6cfa51d 100644 --- a/src/hooks/use-web-3-auth.tsx +++ b/src/hooks/use-web-3-auth.tsx @@ -3,6 +3,7 @@ import { CHAIN_NAMESPACES } from "@web3auth/base"; import type { Web3Auth } from "@web3auth/modal"; import { createContext, useContext, useEffect, useState } from "react"; import type { Chain } from "viem/chains"; +import { WEB3AUTH_RPC_TARGETS } from "../config/iq-login.config"; export interface Web3AuthContextType { web3Auth: Web3Auth | null; @@ -45,11 +46,12 @@ export function Web3AuthProvider({ const chainConfig = { chainNamespace: CHAIN_NAMESPACES.EIP155, chainId: `0x${chain.id.toString(16)}`, - rpcTarget: chain.rpcUrls.default.http[0], + rpcTarget: + WEB3AUTH_RPC_TARGETS[chain.id] ?? chain.rpcUrls.default.http[0], displayName: chain.name, tickerName: chain.nativeCurrency?.name, ticker: chain.nativeCurrency?.symbol, - blockExplorerUrl: chain.blockExplorers?.default.url[0] as string, + blockExplorerUrl: chain.blockExplorers?.default.url as string, }; await web3AuthInstance.addChain(chainConfig); From c04d5662109d77b6c5e2a724fdcab0c47d47d37c Mon Sep 17 00:00:00 2001 From: Kelechi Date: Tue, 5 May 2026 14:10:31 +0100 Subject: [PATCH 2/3] fix: remove unsafe type assertions on blockExplorerUrl blockExplorers is optional on Chain type, so the `as string` assertion masks a potential undefined. Since Web3Auth's blockExplorerUrl config is also optional, let the type system handle it correctly. --- src/config/iq-login.config.ts | 2 +- src/hooks/use-web-3-auth.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/iq-login.config.ts b/src/config/iq-login.config.ts index 1813430..1ca25b9 100644 --- a/src/config/iq-login.config.ts +++ b/src/config/iq-login.config.ts @@ -101,7 +101,7 @@ function createWeb3AuthInstance(defaultChain: Chain) { displayName: defaultChain.name, tickerName: defaultChain.nativeCurrency?.name, ticker: defaultChain.nativeCurrency?.symbol, - blockExplorerUrl: defaultChain.blockExplorers?.default.url as string, + blockExplorerUrl: defaultChain.blockExplorers?.default.url, }; // Initialize Web3Auth with the default chain diff --git a/src/hooks/use-web-3-auth.tsx b/src/hooks/use-web-3-auth.tsx index 6cfa51d..28b5733 100644 --- a/src/hooks/use-web-3-auth.tsx +++ b/src/hooks/use-web-3-auth.tsx @@ -51,7 +51,7 @@ export function Web3AuthProvider({ displayName: chain.name, tickerName: chain.nativeCurrency?.name, ticker: chain.nativeCurrency?.symbol, - blockExplorerUrl: chain.blockExplorers?.default.url as string, + blockExplorerUrl: chain.blockExplorers?.default.url, }; await web3AuthInstance.addChain(chainConfig); From e0e9ab0b9b38defdc502f606d205f5087e8fc0ec Mon Sep 17 00:00:00 2001 From: Kelechi Date: Tue, 5 May 2026 14:17:45 +0100 Subject: [PATCH 3/3] chore: remove verbose comments from RPC targets --- src/config/iq-login.config.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/config/iq-login.config.ts b/src/config/iq-login.config.ts index 1ca25b9..9970868 100644 --- a/src/config/iq-login.config.ts +++ b/src/config/iq-login.config.ts @@ -35,14 +35,9 @@ export interface IqLoginConfig { chains: [Chain, ...Chain[]]; } -// Reliable public RPCs for Web3Auth's provider setup. -// Viem's default RPCs can be unreliable for eth_getBlockByNumber which -// Web3Auth's TransactionFormatter.getEIP1559Compatibility calls during -// provider setup after OAuth. e.g. eth.merkle.io times out on this call, -// polygon-rpc.com returns no result. PublicNode handles these reliably. export const WEB3AUTH_RPC_TARGETS: Record = { - 1: "https://ethereum-rpc.publicnode.com", // Ethereum Mainnet - 137: "https://polygon-bor-rpc.publicnode.com", // Polygon + 1: "https://ethereum-rpc.publicnode.com", + 137: "https://polygon-bor-rpc.publicnode.com", }; export function createIqLoginConfig(