What is Web3Auth?
Visit Web3Auth docs to get more information.
Before Starting
You can start this tutorial if you already have a NextJS dapp with MetaMask sign-in functionality.Installing the Web3Auth Wagmi Connector Install the@web3auth/web3auth-wagmi-connector dependency:
npm2yarn
Configuring the Web3Auth Wagmi Connector
- Open the
pages/signin.jsxfile and addWeb3AuthConnectoras a connector to theuseConnect()hook:
Testing the Web3Auth Connector
Visithttp://localhost:3000/signin to test authentication.
- Click on
Authenticate via Web3Auth - Select the preferred sign-in method
- After successful authentication, you will be redirected to the
/userpage - Visit
http://localhost:3000/userto test the user session’s functionality:
- When a user is authenticated, we show the user’s info on the page.
- When a user is not authenticated, we redirect to the
/signinpage. - When a user is authenticated, we show the user’s info on the page, even refreshing after the page. (
Explanation: After Web3 wallet authentication, the next-auth library creates a session cookie with an encrypted JWT [JWE] stored inside. It contains session info [such as an address and signed message] in the user's browser.)

