Skip to main content
Verify users with TOTP-based MFA by requesting and submitting a 6-digit code from their authenticator app.

Requesting an MFA challenge

To request an MFA challenge for the current user, call the init method from the useMfa hook, passing 'totp' as the MFA method parameter:
import {useMfa} from '@privy-io/react-auth';

const {init, submit} = useMfa();

// Request a TOTP MFA challenge
await init('totp');
The init method will prepare an MFA challenge for the TOTP method. The user will receive the MFA code within their authenticator app. The method returns a Promise that resolves if the challenge was successfully created, and rejects with an error if there was an issue.

Submitting the MFA verification

Once init has resolved successfully, prompt the user to get their MFA code from their authenticator app and enter it within your app. Then, call the submit method from useMfa. As parameters, pass the MFA method ('totp') and the MFA code that the user entered:
const mfaCode = 'insert-mfa-code-from-user';
await submit('totp', mfaCode);
When submit resolves successfully, the user has completed MFA and can proceed to use their embedded wallet.