Overview
The @djuno/web3auth-hook
package simplifies integration with the @djuno/web3auth-sdk
by providing a Web3authProvider
and useWeb3Auth
hook. It manages:
API client setup
Network and profile fetching
Authentication handshake and verification
Avatar upload and retrieval
Loading states per method
Use this hook when you want to handle Web3Auth flows (e.g., wallet signature verification) in a React-friendly way.
Usage
1. Install the package
npm install @djuno/web3auth-hook
2. Wrap your app with Web3authProvider
import { Web3authProvider } from '@djuno/web3auth-hook';
const App = () => {
return (
<Web3authProvider clientConfigs={{
accessKey: 'YOUR_ACCESS_KEY', // Required
endpointUrl: 'https://web3auth.djuno.cloud', // Optional
}}
>
<YourApp />
</Web3authProvider>
);
};
3. Use the useWeb3Auth
hook
import { useWeb3Auth } from '@djuno/web3auth-hook';
const Example = () => {
const {
getNetworks,
handshake,
verify,
getProfile,
updateProfile,
getProfileAvatar,
saveProfileAvatar,
setAccessKey,
networks,
profile,
profileAvatar,
loading
} = useWeb3Auth();
// Example usage
const handleAuth = async () => {
const networks = await getNetworks();
const signature = await handshake(networks[0].Id, '0xPUBLIC_KEY');
const token = await verify(networks[0].Id,'0xPUBLIC_KEY',signature);
await getProfile(token);
};
return <button onClick={handleAuth}>Authenticate</button>;
};
API
Provider
<Web3authProvider clientConfigs={...}>
Wraps your app and provides the @djuno/web3auth-sdk
client to the hook.
clientConfigs
:ClientConfigs
β passed to theClient
constructor.
Hook
useWeb3Auth()
Returns the following:
Property | Type | Description |
|
| The internal SDK client instance. |
|
| Loading state per method. |
|
| Fetch available networks. |
|
| Cached networks from |
|
| Starts the handshake and returns a challenge/signature. |
|
| Verifies the signature and returns a JWT token. |
|
| Fetches and stores the user profile. |
|
| Cached profile object. |
|
| Updates profile data. |
|
| Fetches avatar as a blob URL. |
|
| Cached avatar blob URL. |
|
| Saves profile avatar. |
|
| Updates the API key dynamically. |