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 a verification code to complete a sensitive action.
The core features include:
- TOTP (Time-based One-Time Password) verification via authenticator apps
- SMS verification via phone number
- Method selection when the user has multiple methods enrolled
- 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: Manages the verification form and multi-method navigationVerifyMfaFlowBackButton: A button to navigate back within the multi-method flowVerifyMfaItems: Renders the list of alternate MFA methodsVerifyMfaItem: Renders an individual MFA method itemVerifyMfaFooter: 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 ("totp"or"sms")methods: Array of the user’s enrolled MFA methodsstep: The current step ("verification"or"list")flowDirection: The direction of the transition animationmfaCode: 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 manages the verification form and multi-method navigation. When the user has multiple enrolled methods, a “Use a different method” button is shown, allowing the user to switch between methods. The flow handles transitions between the verification screen and the method selection list.
VerifyMfaFlow provides a children render prop that receives the current step, method, and the Content component.
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. - Supported methods: TOTP (authenticator app) and SMS verification are supported. The available methods are determined by the user’s enrolled MFA methods.
- Multi-method navigation: When a user has multiple enrolled methods, a “Use a different method” button allows switching between them.
- SMS resend: SMS verification includes a resend option with a cooldown timer.
- Automatic form submission: The verification form automatically submits when the user enters a complete 6-digit code.