Skip to main content
function registerMfaListener(listener: MfaListener, options?: MfaListenerOptions): () => void;
Registers an MFA verification listener. Listeners can be global (no scope) or scoped to a specific DOM element. The event bubbles up from the trigger element through the DOM:
  • Scoped listeners listen on their container and catch events from within
  • Global listeners listen on document and catch anything that bubbles up

Parameters

ParameterTypeDescription
listenerMfaListenerThe listener function to call when MFA is required.
options?MfaListenerOptionsOptional configuration including scope element.

Returns

A function to unregister the listener.
(): void;

Returns

void

Example

// Global listener (responds to any MFA trigger not handled by a scoped listener)
const unregisterGlobal = registerMfaListener(({ methods }) => {
  openMfaModal(methods);
});

// Scoped listener (only responds to triggers inside the container)
const container = document.getElementById('my-flow');
if (container) {
  const unregisterScoped = registerMfaListener(
    ({ methods }) => showInlineMfa(methods),
    { scope: container }
  );
  // Later, when done:
  unregisterScoped();
}

// Clean up global listener when done:
unregisterGlobal();