Overview
TheVerifyMfa component provides a solution for prompting users to verify their identity using multi-factor authentication. It is designed for users who have already enrolled in MFA and need to enter their authenticator code to complete a sensitive action.
The core features include:
- TOTP (Time-based One-Time Password) verification via authenticator apps
- Clean, focused verification interface
- Composable UI that gives developers full control over layout and styling
- Success and error callbacks for handling verification results
- Centralized state management for the verification process
Architecture
The component is built using a composition pattern that allows for maximum flexibility while providing sensible defaults when customization is not needed.Composition model
TheVerifyMfa component is composed of several subcomponents that work together to create the verification experience. This approach allows developers to customize the UI structure while maintaining the underlying functionality.
The main components are:
VerifyMfa: The root wrapper component that provides theVerifyMfaContextand manages stateVerifyMfaTitle: Renders the title for the verification interfaceVerifyMfaDescription: Renders the description/instructionsVerifyMfaImage: Renders the verification icon/imageVerifyMfaFlow: Renders the verification form with OTP inputVerifyMfaFooter: The “Secured by Coinbase” footer
VerifyMfa
TheVerifyMfa component accepts a children prop that can be either React nodes or a render function. When using a render function, it receives the current VerifyMfaState as an argument, providing access to all state values without needing to use the useVerifyMfaContext hook directly.
Example of children as a render function:
State management (VerifyMfaProvider and VerifyMfaContext)
The entire verification flow’s state is managed byVerifyMfaProvider and accessed via the useVerifyMfaContext hook. This context contains:
method: The currently selected MFA method (currently only “totp”)methods: Array of available MFA methods for verificationstep: The current step (currently only “verification”)mfaCode: The verification code entered by the usererror: Any error that occurred during verificationisPending: Whether a verification request is in progressisSuccess: Whether the verification was successful
VerifyMfaFlow
TheVerifyMfaFlow component renders the OTP input form. It handles user input, form submission, and displays loading/success states.
Example: Basic usage
Implement a simple MFA verification prompt:Example: Custom layout
Customize the verification interface:Example: Accessing state with render function
Use the render function pattern for state access:API Reference
Optional Props
onSuccess: Callback function invoked when verification is successful. Receives the MFA code as an argument.onError: Callback function invoked when verification fails. Receives the error object.children: React nodes for custom layout, or a function that receivesVerifyMfaStateclassName: Additional CSS classes to apply to the root element
Notes
- For enrolled users only: This component is designed for users who have already completed MFA enrollment. Use
EnrollMfafor the enrollment flow. - Currently supports TOTP only: The component is designed to support multiple MFA methods, but currently only TOTP (authenticator app) verification is available.
- Automatic form submission: The verification form automatically submits when the user enters a complete 6-digit code.