For new React apps, we recommend the JavaScript SDK with React Hooks (@dynamic-labs-sdk/react-hooks) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the React quickstart (JavaScript SDK) to get started.
MFA enrollment requires users to register a TOTP device or Passkey. Configure it in the dashboard before implementing in your application. See End-User MFA - Enrollment for dashboard setup instructions.
With the Dynamic UI, MFA enrollment prompts appear automatically during onboarding/login when additional authentication is required. To explicitly trigger in your app, use useSyncMfaFlow to detect the requirement and usePromptMfaAuth to open the UI.Note: The Dynamic UI is method-agnostic. It automatically prompts with whichever MFA method(s) you have enabled (TOTP and/or Passkeys), so separate TOTP/Passkey tabs are not required here.
import { useSyncMfaFlow, useDynamicContext, usePromptMfaAuth } from "@dynamic-labs/sdk-react-core";const { userWithMissingInfo } = useDynamicContext();const promptMfaAuth = usePromptMfaAuth();useSyncMfaFlow({ handler: async () => { if (userWithMissingInfo?.scope?.includes("requiresAdditionalAuth")) { // Opens the Dynamic UI to complete MFA enrollment await promptMfaAuth(); // No MFA token needed for enrollment } },});
useSyncMfaFlow hook to detect the requirement and open the Dynamic UI
usePromptMfaAuth hook to prompt the user to authenticate with MFA
Dynamic SDKs provide granular control over individual MFA modal screens. These methods allow you to programmatically show and hide specific MFA screens in your application.