useAuthTokenInfo
Hook to retrieve the identity token (JWT) for the signed-in user. Verify this token on your backend
to confirm the user's identity. This hook replaces the deprecated
useIdentityToken.
Import
import { useAuthTokenInfo } from '@web3auth/react-native-sdk'
Usage
import { useAuthTokenInfo } from '@web3auth/react-native-sdk'
import { Button, Text, View } from 'react-native'
function VerifyButton() {
const { getAuthTokenInfo, loading, error } = useAuthTokenInfo()
const verifyOnServer = async () => {
const idToken = await getAuthTokenInfo()
if (!idToken) return
await fetch('https://<YOUR_BACKEND>/api/verify', {
method: 'POST',
headers: { Authorization: `Bearer ${idToken}` },
})
}
return (
<View>
<Button
title={loading ? 'Fetching token…' : 'Verify identity'}
disabled={loading}
onPress={verifyOnServer}
/>
{error && <Text>{error.message}</Text>}
</View>
)
}
See identity token verification for how to validate the token on your server.
Return type
import { type IUseAuthTokenInfo } from '@web3auth/react-native-sdk'
getAuthTokenInfo
() => Promise<string | null>
Resolves with the identity token for the current session. Resolves with null and sets error if
the user isn't signed in. For sessions created by passing an idToken to connectTo, the hook
returns the token you passed.
token
string | null
Most recent identity token returned by getAuthTokenInfo. Resets to null when the session is no
longer authorized. Sessions created by passing an idToken to connectTo are never authorized, so
for them token stays null; use the value getAuthTokenInfo returns instead.
loading
boolean
true while getAuthTokenInfo runs.
error
Web3authRNError | null
Error from the most recent getAuthTokenInfo call, or null.