- React
- React Native
The React SDK will automatically prompt users for their auth factor on new devices when they use their wallet. There is no additional logic your application must implement to handle this.
When a user uses their embedded wallet on a new device for the first time, the wallet must first be recovered on that deviceBy default, wallets created for your users will be automatically provisioned and should never need recovery. For these wallets, you can skip these steps and directly request a signature or transaction.
For wallets where the
recovery_method is 'privy' the wallet will be automatically recovered
and should never need recovery. For these wallets, you can skip these steps and directly request a
signature or transaction.Setting up your recovery listener
The wallet must be recovered before you can request signatures or transact with the embedded wallet. The React Native SDK will try to recover the user’s wallet once you start interacting with it. We recommend that you set up a global listener on your application to handle manual recovery in a single place.To set up this configuration, use Privy’suseOnNeedsRecovery hook.
AS a parameter, you must pass in an object defining the the onNeedsRecovery callback.onNeedsRecovery will receive two parameters to drive what recovery looks like:| Parameter | Type | Description |
|---|---|---|
recoveryMethod | "privy" | "user-passcode" | "google-drive" | "icloud" | "recovery-encryption-key" | An enum representing the recovery method used for this user. |
onRecovered | () => void | This is a callback function you should call once recovery has been completed. It takes no arguments. |
Report incorrect code
Copy
Ask AI
import {useOnNeedsRecovery, useRecoverEmbeddedWallet} from '@privy-io/expo';
// This could live in a different screen,
// e.g. if you navigate to a recovery screen when the listener is triggered
const {recover} = useRecoverEmbeddedWallet();
useOnNeedsRecovery({
onNeedsRecovery: async ({recoveryMethod, onRecovered}) => {
if (recoveryMethod === 'user-passcode') {
// Get the passcode from the user, e.g. by prompting some UI
const password = 'user-provided-passcode';
await recover({recoveryMethod, password});
// Remember to call this after recovery has been completed.
onRecovered();
}
}
});
Recovering the wallet
To recover an embedded wallet for your user, use therecover function returned by the Privy React Native SDK’s useRecoverEmbeddedWallet hook.You can determine the proper arguments for recover via the account.recovery_method property on the embedded wallet account:user-passcode, callrecoverwithrecoveryMethod: 'user-passcode'and the user inputpassword.google-drive, call recover withrecoveryMethod: 'google-drive'.icloud, call recover withrecoveryMethod: 'icloud'. Note: this is only supported on iOS devices.

