Skip to content

Upgrading recovery

Once a wallet has been created, users have the ability to upgrade from automatic recovery to a user-owned recovery method, or to switch between different user-owned recovery methods.

INFO

Please note that:

  • If a user's embedded wallet requires recovery or MFA, they will need to complete those check(s) before upgrading their recovery method.
  • Once a wallet is upgraded to a user-owned recovery method, it cannot be set back to automatic recovery.

Upgrading a user's recovery method

To prompt users to set or upgrade recovery on their wallet, call the setWalletRecovery method from the useSetWalletRecovery hook.

tsx
const {setWalletRecovery} = useSetWalletRecovery();

This method will open a modal where the user can choose from the user-controlled recovery methods you have enabled in the Dashboard. This will always include setting up a password or resetting their password as an option.

When invoked, setWalletRecovery will return a Promise for the embedded wallet's updated Wallet object, that will resolve once the user has successfully set recovery for their wallet.

The method will reject with an error if the user does not have an embedded wallet, or if the user cancels the flow at any period. To determine if a user's embedded wallet is already secured by a user-owned recovery method, check if the embedded wallet's entry in the user.linkedAccounts array has a recoveryMethod that isn't privy (automatic recovery).

TIP

Users can reset their password using this method as well.

As an example, you might add setWalletRecovery as an event handler for a set recovery button in your app:

tsx
import {usePrivy} from '@privy-io/react-auth';

// This example assumes you have already checked that Privy is `ready` and the user is `authenticated`
function AddOrUpdateRecoveryButton() {
  const {user} = usePrivy();
  const {setWalletRecovery} = useSetWalletRecovery();
  const embeddedWallet = user.linkedAccounts.find(
    (account): account is WalletWithMetadata =>
      account.type === 'wallet' && account.walletClientType === 'privy',
  );
  const alreadyHasUserOwnedRecovery = embeddedWallet.recoveryMethod !== 'privy';

  return (
    <button onClick={setWalletRecovery}>
      {!alreadyHasUserOwnedRecovery
        ? 'Add recovery to your wallet'
        : 'Update recovery on your wallet'}
    </button>
  );
}