Skip to main content

@MFADeviceRemovedHook()

Package: @nauth-toolkit/nestjs Type: Class Decorator

Class decorator that automatically registers a provider as an MFA device removed hook. Executes after MFA device removal. Non-blocking - errors are logged but don't affect removal.

Overview​

The @MFADeviceRemovedHook() decorator enables automatic hook registration. Classes decorated with this decorator are discovered at module initialization and registered with the HookRegistryService.

Key Features:

  • Automatic hook discovery and registration
  • Full dependency injection support
  • Executes in NAuthHooksModule.forFeature() registration order
  • Non-blocking - errors don't affect removal

Usage​

Basic Hook​

import { Injectable } from '@nestjs/common';
import {
MFADeviceRemovedHook,
IMFADeviceRemovedHook,
MFADeviceRemovedMetadata,
} from '@nauth-toolkit/nestjs';

@Injectable()
@MFADeviceRemovedHook()
export class MFADeviceRemovedAlertHook implements IMFADeviceRemovedHook {
constructor(private readonly emailService: EmailService) {}

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

Module Registration​

import { Module } from '@nestjs/common';
import { AuthModule, NAuthHooksModule } from '@nauth-toolkit/nestjs';
import { MFADeviceRemovedAlertHook } from './hooks/mfa-device-removed.hook';

@Module({
imports: [
AuthModule.forRoot(authConfig),
NAuthHooksModule.forFeature([MFADeviceRemovedAlertHook]),
],
})
export class CustomAuthModule {}