Skip to main content

IMFADeviceRemovedHook

Hook interface for executing actions after MFA device removal.

Overview​

The IMFADeviceRemovedHook interface enables reactions to MFA device removal events, whether initiated by users or system automation.

The hook is non-blocking - errors are logged but do not affect the removal operation.

Interface​

interface IMFADeviceRemovedHook {
execute(metadata: MFADeviceRemovedMetadata): Promise<void>;
}

Metadata​

MFADeviceRemovedMetadata​

interface MFADeviceRemovedMetadata {
user: IUser;
deviceType: MFADeviceMethod;
deviceName?: string;
removedBy: 'user' | 'system';
reason?: string;
remainingDeviceCount: number;
clientInfo?: ClientInfo;
}
PropertyTypeDescription
userIUserUser whose device was removed
deviceTypeMFADeviceMethodType of MFA device removed
deviceNamestringDevice name (user-provided label)
removedBy'user' | 'system'Who removed the device
reasonstringReason for removal
remainingDeviceCountnumberMFA devices remaining after removal
clientInfoClientInfoIP, user agent, location

When Hook Fires​

  • User removes MFA device via removeDevices()
  • System removes device due to email/phone change via updateUserAttributes()

Example​

import { IMFADeviceRemovedHook, MFADeviceRemovedMetadata } from '@nauth-toolkit/core';

export class MFADeviceRemovedAlertHook implements IMFADeviceRemovedHook {
async execute(metadata: MFADeviceRemovedMetadata): Promise<void> {
await this.emailService.sendMFADeviceRemovedEmail({
to: metadata.user.email,
deviceType: metadata.deviceType,
remainingDevices: metadata.remainingDeviceCount,
});
}
}