Archived Content from Web3Auth Community
This topic was originally posted by jonwayhuang on 6/4/2025.
This content has been migrated from our previous community forum to preserve valuable discussions.
When asking for help in this category, please make sure to provide the following details:
- SDK Version(package.json): ^10.0.2
- Platform: Next.js
- Browser Console Screenshots:
Following the QuickStart guide and Next.js guide, I realized the hooks to get idToken do not work.
import { useWeb3Auth, useIdentityToken, useWeb3AuthUser } from "@web3auth/modal/react";
export default function App() {
const { initError, isConnected } = useWeb3Auth(); // isConnected is true immediately after page refresh
const { token, getIdentityToken } = useIdentityToken();
const { userInfo } = useWeb3AuthUser();
âŚ
}
On a page refresh, both token and userInfo returns undefined. At no point does it return a valid value (even after waiting 10s and all hooks stop running). However, when I get the token after wagmi is connected with the following code:
const { address, isConnected: isWagmiConnected } = useAccount();
useEffect(() => {
async function getToken() {
const _token = await getIdentityToken();
console.log(âPayments.tsx, useEffect, _token:â, _token);
}
getToken();
}, [isWagmiConnected]);
Then I successfully get the idToken. I think the web3Auth hooks need to be better optimized. Specifically, the hooks need to run again after initialization, thus providing the updated values (which takes around ~5s), which is what the Wagmi useAccount hook successfully does (I get the updated isConnected and address value ~5s after a page refresh).