Skip to main content

useWeb3AuthUser

Hook to fetch and manage the current Embedded Wallets user information.

info

Please note that this hook doesn't work for external wallet logins. It only works for social login embedded wallets. It returns and empty object for external wallet logins.

Import

import { useWeb3AuthUser } from '@web3auth/modal/react'

Usage

import { useWeb3AuthUser } from '@web3auth/modal/react'

function UserInfo() {
const { userInfo, loading, error, isMFAEnabled, getUserInfo } = useWeb3AuthUser()

if (loading) return <div>Loading user info...</div>
if (error) return <div>Error: {error.message}</div>
if (!userInfo) return <div>No user info available.</div>

return (
<>
<div>
<pre>{JSON.stringify(userInfo, null, 2)}</pre>
<div>MFA Enabled: {isMFAEnabled ? 'Yes' : 'No'}</div>
<button onClick={() => getUserInfo()}>Refresh User Info</button>
</div>
{error && <div>{error.message}</div>}
</>
)
}

Return type

import { type IUseWeb3AuthUser } from '@web3auth/modal/react'

loading

boolean

Whether the user info fetching process is in progress.

error

Web3AuthError | null

Error that occurred during the user info fetching process.

userInfo

Partial<UserInfo> | null

The current user's information, or null if not available.

isMFAEnabled

boolean

Whether Multi-Factor Authentication (MFA) is enabled for the user.

getUserInfo

() => Promise<Partial<UserInfo> | null>

Function to fetch the latest user information from Web3Auth.