useIdentityToken
Hook to retrieve and manage the identity token from Web3Auth.
Import
import { useIdentityToken } from "@web3auth/modal/react";
Usage
import { useIdentityToken } from "@web3auth/modal/react";
function IdentityTokenButton() {
const { getIdentityToken, loading, error, token } = useIdentityToken();
return (
<div>
<button onClick={() => getIdentityToken()} disabled={loading}>
{loading ? "Authenticating..." : "Get Identity Token"}
</button>
{token && <div>Token: {token}</div>}
{error && <div>Error: {error.message}</div>}
</div>
);
}
Return Type
import { type IUseIdentityToken } from "@web3auth/modal/react";
loading
boolean
Whether the authentication process is in progress.
error
Web3AuthError | null
Error that occurred during the authentication process.
token
string | null
The identity token returned after successful authentication.
getIdentityToken
() => Promise<string | null>
Function to initiate the authentication process and retrieve the identity token.