> ## Documentation Index
> Fetch the complete documentation index at: https://www.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Check Recovery Codes Acknowledgment

# 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

```javascript theme={"system"}
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

| Parameter | Type                       | Description                                                             |
| --------- | -------------------------- | ----------------------------------------------------------------------- |
| `client`  | `DynamicClient` (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

```javascript theme={"system"}
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

```javascript theme={"system"}
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

```javascript theme={"system"}
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

```javascript theme={"system"}
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

```javascript theme={"system"}
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:

```typescript theme={"system"}
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:

```javascript theme={"system"}
import { isPendingRecoveryCodesAcknowledgment } from '@dynamic-labs-sdk/client';

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

## React

`isPendingRecoveryCodesAcknowledgment()` is synchronous — call it during render. Pair it with `useUser()` so the component re-renders once the user acknowledges their codes:

```tsx theme={"system"}
import { isPendingRecoveryCodesAcknowledgment } from '@dynamic-labs-sdk/client';
import { useUser } from '@dynamic-labs-sdk/react-hooks';

function RecoveryCodesGate({ children }: { children: React.ReactNode }) {
  const { data: user } = useUser(); // re-renders on userChanged

  if (!user) return null;
  if (isPendingRecoveryCodesAcknowledgment()) return <AcknowledgeRecoveryCodesPrompt />;

  return <>{children}</>;
}
```

## Related

* [acknowledgeRecoveryCodes](/javascript/authentication-methods/mfa/recovery-codes#acknowledging-recovery-codes) - Mark recovery codes as acknowledged
* [getMfaRecoveryCodes](/javascript/authentication-methods/mfa/recovery-codes#getting-recovery-codes) - Get user's recovery codes
* [isUserOnboardingComplete](/javascript/authentication-methods/is-user-onboarding-complete) - Check if user completed all onboarding requirements
* [isUserMissingMfaAuth](/javascript/authentication-methods/is-user-missing-mfa-auth) - Check if user needs MFA authentication
* [Recovery Codes Guide](/javascript/authentication-methods/mfa/recovery-codes) - Complete guide to recovery codes
