Thanks for sharing your detailed setup and code snippets! Here’s a summary of your issue for the support team:
Issue Summary
SDK Details: Web3Auth Plug n Play, using @web3auth/modal/react and SSR (Next.js 13+ with app directory)
Platform: Next.js (SSR, app directory)
SDK Version: Not specified (please confirm if not latest)
Issue:
After switching the network in your dApp, if you refresh the page, the app does not stay connected to the newly selected network—it reverts to the default.
Code Provided:
Provider.tsx (Web3Auth + Wagmi + SSR setup)
Layout.tsx (SSR state hydration using cookieToWeb3AuthState)
Next Steps & Information Needed
To help the support team reproduce and resolve this, could you clarify a couple of points:
Network Switching Implementation:
How are you handling the network switch? Are you using Wagmi’s switchNetwork or a custom method?
Is the selected network stored anywhere (e.g., in cookies, localStorage, or app state) to persist across reloads?
Web3Auth State Persistence:
The code shows SSR state hydration for authentication, but network selection is not part of the Web3Auth state by default.
Are you expecting Web3Auth to remember the network, or are you handling network persistence separately?
SDK Version:
Which versions of @web3auth/modal and related packages are you using? (If possible, please share your package.json dependencies for these.)
Console Errors:
Are there any errors or warnings in the browser console after refreshing?
Possible Solution & References
Network Persistence:
Web3Auth manages authentication state, but network selection (e.g., Ethereum Mainnet, Polygon, etc.) is typically managed by your dApp logic or Wagmi.
To persist the network across reloads, you may need to:
Store the selected network in a cookie or localStorage on network switch
On app load, read the stored value and initialize Wagmi/Web3Auth with that network
On network switch, save the selected network to localStorage or a cookie.
On SSR hydration, read this value and set the initial network for Wagmi/Web3Auth.
Let us know the details above, and we can guide you with a code example if needed!
If you have screenshots or a minimal reproduction repo, feel free to share those as well.
Thanks for your detailed report—looking forward to helping you resolve this!
Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.
Additionally, we would recommend you to join our biweekly Office Hours to get this resolved even faster. Web3Auth Developer Office Hours
Interestingly, the network switching now works as expected—cookies are updating correctly, and the switched network persists on refresh.
That said, I’m still encountering the following issues:
Logout with External Wallet (MetaMask):
On first login, MetaMask is detected properly. But after logging out and attempting to log in again, MetaMask is no longer recognized—the UI instead prompts to install it.
Switching from Social Login to External Wallet:
After logging in with a social provider and then logging out, logging in again using an external wallet results in the useAccount hook from Wagmi returning undefined instead of the connected wallet address.
Just to clarify, I’m seeing these issues on the “web3auth-examples” main branch without making any code changes.
Thanks for pointing this out. Our system somehow didn’t track your latest reply causing the delay. Please try our latest patch version 10.04 which fixes most of these issues. Let us know if you are still facing it.