A step-by-step guide to implementing Passkey MFA with a custom UI using Dynamic’s headless hooks.
@dynamic-labs/sdk-react-core
and set up your component’s state. You’ll need state for managing passkeys, recovery codes, and any potential errors. The primary hooks used are useRegisterPasskey
to add a new passkey and useAuthenticatePasskeyMFA
to verify one.
useGetPasskeys
hook to fetch and display any passkeys the user has already registered. This is typically done inside a useEffect
hook that runs when the user is logged in.
useSyncMfaFlow
hook is essential for account-based MFA. It automatically detects if an MFA challenge is required for the current user. If it is, the handler
function is called, allowing you to trigger the appropriate action—either registering a new passkey if none exist, or authenticating an existing one.
registerPasskey
and authenticatePasskeyMFA
functions from their respective hooks. These functions will trigger the browser’s native passkey UI. For action-based MFA, you can pass a createMfaToken
option to authenticatePasskeyMFA
to generate a token for authorizing sensitive actions.
View Complete Example
useGetMfaToken
.singleUse: true
) or one that persists for the user’s session (singleUse: false
).getMfaToken()
to check for an existing token before attempting to create a new one.