Skip to main content

isPendingRecoveryCodesAcknowledgment

Checks if the user is still pending acknowledgment of their MFA recovery codes. This function determines whether the user has been presented with recovery codes that they have not yet acknowledged as saved or backed up. When MFA is set up, users receive recovery codes that can be used to regain access if they lose their MFA device. It’s important to ensure users acknowledge these codes before proceeding.

Usage

import { isPendingRecoveryCodesAcknowledgment } from '@dynamic-labs-sdk/client';

const checkRecoveryCodesStatus = () => {
  const isPending = isPendingRecoveryCodesAcknowledgment();

  if (isPending) {
    console.log('User needs to acknowledge recovery codes');
  } else {
    console.log('Recovery codes have been acknowledged');
  }
};

Parameters

ParameterTypeDescription
clientDynamicClient (optional)The Dynamic client instance. Only required when using multiple clients.

Returns

boolean - Returns true if recovery codes are pending acknowledgment, false otherwise.

Examples

Prompt user to acknowledge recovery codes

import {
  isPendingRecoveryCodesAcknowledgment,
  acknowledgeRecoveryCodes
} from '@dynamic-labs-sdk/client';

const handlePostMfaSetup = async () => {
  if (isPendingRecoveryCodesAcknowledgment()) {
    // Show recovery codes and prompt for acknowledgment
    const confirmed = await showRecoveryCodesPrompt();

    if (confirmed) {
      // User confirms they've saved the codes
      await acknowledgeRecoveryCodes();
      console.log('Recovery codes acknowledged');
    }
  }
};

Block access until acknowledgment

import { isPendingRecoveryCodesAcknowledgment } from '@dynamic-labs-sdk/client';

const canAccessFeature = () => {
  if (isPendingRecoveryCodesAcknowledgment()) {
    console.log('Access blocked: Please acknowledge your recovery codes');
    return false;
  }

  return true;
};

Conditional UI rendering

import {
  isPendingRecoveryCodesAcknowledgment,
  getMfaRecoveryCodes
} from '@dynamic-labs-sdk/client';

const renderMfaSetupFlow = async () => {
  const isPending = isPendingRecoveryCodesAcknowledgment();

  if (isPending) {
    // Get and display recovery codes
    const { recoveryCodes } = await getMfaRecoveryCodes();

    return (
      <div>
        <h2>Save Your Recovery Codes</h2>
        <p>Store these codes in a secure location:</p>
        <ul>
          {recoveryCodes.map((code) => (
            <li key={code}>{code}</li>
          ))}
        </ul>
        <button onClick={handleAcknowledge}>
          I've saved my recovery codes
        </button>
      </div>
    );
  }

  return <CompleteMfaSetup />;
};

Check during onboarding

import {
  isPendingRecoveryCodesAcknowledgment,
  isUserOnboardingComplete
} from '@dynamic-labs-sdk/client';

const checkOnboardingProgress = () => {
  const needsRecoveryCodes = isPendingRecoveryCodesAcknowledgment();
  const isFullyOnboarded = isUserOnboardingComplete();

  console.log('Needs recovery code acknowledgment:', needsRecoveryCodes);
  console.log('Fully onboarded:', isFullyOnboarded);

  if (needsRecoveryCodes) {
    showRecoveryCodesStep();
  } else if (!isFullyOnboarded) {
    showNextOnboardingStep();
  } else {
    showMainApplication();
  }
};

Listen for user state changes

import {
  isPendingRecoveryCodesAcknowledgment,
  onEvent
} from '@dynamic-labs-sdk/client';

// Monitor recovery code acknowledgment status
onEvent({
  event: 'userChanged',
  listener: ({ user }) => {
    if (!user) return;

    const isPending = isPendingRecoveryCodesAcknowledgment();

    if (isPending) {
      console.log('Show recovery codes prompt');
      showRecoveryCodesModal();
    } else {
      console.log('Recovery codes acknowledged');
      hideRecoveryCodesModal();
    }
  },
});

How it works

The function checks the user’s mfaBackupCodeAcknowledgement status:
user.mfaBackupCodeAcknowledgement !== MfaBackupCodeAcknowledgement.Complete
The status can be:
  • pending: User has been given recovery codes but hasn’t acknowledged them
  • complete: User has acknowledged their recovery codes
  • null or undefined: Treated as pending (user hasn’t explicitly completed acknowledgment)
The function returns true for any status that is not explicitly complete, ensuring users must actively acknowledge their recovery codes.

When does this apply?

This check is relevant when:
  • A user has set up MFA for the first time
  • A user has created new recovery codes
  • MFA is required by your application settings
If MFA is not enabled or the user hasn’t set up MFA, this will typically return false.

Error handling

The function throws an error if the user is not logged in:
import { isPendingRecoveryCodesAcknowledgment } from '@dynamic-labs-sdk/client';

try {
  const isPending = isPendingRecoveryCodesAcknowledgment();
} catch (error) {
  console.error('User not logged in:', error);
}