Skip to main content

Summary

This hook provides a way for clients to prompt the user to authenticate with MFA via the Dynamic UI. It supports both the legacy createMfaToken flow and the recommended requestedScopes flow for elevated access tokens. The hook needs to be initialized within a child of DynamicContextProvider.

Parameters

PropertyTypeDescription
requestedScopesTokenScope[]Scopes to request an elevated access token for (recommended)
createMfaTokenboolean@deprecated — Create a single-use MFA token. Use requestedScopes instead.

Usage

import { usePromptMfaAuth } from '@dynamic-labs/sdk-react-core';
import { TokenScope } from '@dynamic-labs/sdk-api-core';

const App = () => {
  const promptMfaAuth = usePromptMfaAuth();

  return (
    <button
      onClick={() => promptMfaAuth({
        requestedScopes: [TokenScope.Walletexport],
      })}
    >
      Prompt MFA
    </button>
  );
};

With MFA token (deprecated)

import { usePromptMfaAuth } from '@dynamic-labs/sdk-react-core';

const App = () => {
  const promptMfaAuth = usePromptMfaAuth();

  return (
    <button
      onClick={() => promptMfaAuth({
        createMfaToken: true,
      })}
    >
      Prompt MFA
    </button>
  );
};