Set user-controlled recovery on the embedded wallet, and to attach callbacks to the wallet’s recovery events.

To prompt users to enroll an auth factor for new devices for their wallet, use the setWalletRecovery method from the useSetWalletRecovery hook:

setWalletRecovery: async () => Promise<void>

When invoked, this method will open a modal where the user can enroll an auth factor for new devices from the options (password, iCloud, Google Drive) you configured in the Dashboard.

Usage

import {useSetWalletRecovery} from '@privy-io/react-auth';
const {setWalletRecovery} = useSetWalletRecovery();

Parameters

This method takes no parameters.

Returns

This method returns a Promise that resolves if the user successfully enrolls an auth factor, and rejects if there is an error.

Callbacks

You can optionally register an onSuccess or onError callback on the useSetWalletRecovery hook.

Usage

const {setWalletRecovery} = useSetWalletRecovery({
    onSuccess: (params: {
        method: UserRecoveryMethod;
        wallet: Wallet;
    }) => {
        console.log('Successfully enrolled auth factor');
    },
    onError: (error) => {
        console.error('Failed to enroll auth factor with error ', error)
    }
})
onSuccess
({method: UserRecoveryMethod, wallet: Wallet}) => void

Optional callback to run after a user successfully enrolls an auth factor.

onError
(error: string) => void

Optional callback to run after there is an error during wallet recovery.