@AccountStatusChangedHook()
Package: @nauth-toolkit/nestjs
Type: Class Decorator
Class decorator that automatically registers a provider as an account status changed hook. Executes after account enable/disable operations. Non-blocking - errors are logged but don't affect status change.
Not in Main Barrel Export
AccountStatusChangedHook is not exported from the @nauth-toolkit/nestjs main entry point. Register this hook manually using HookRegistryService instead of the decorator pattern.
Overview
The @AccountStatusChangedHook() 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
- Priority-based execution ordering
- Non-blocking - errors don't affect status change
Usage
Basic Hook
import { Injectable } from '@nestjs/common';
import {
AccountStatusChangedHook,
IAccountStatusChangedHook,
AccountStatusChangedMetadata,
} from '@nauth-toolkit/nestjs';
@Injectable()
@AccountStatusChangedHook()
export class AccountStatusNotificationHook implements IAccountStatusChangedHook {
constructor(private readonly emailService: EmailService) {}
async execute(metadata: AccountStatusChangedMetadata): Promise<void> {
if (metadata.status === 'disabled') {
await this.emailService.sendAccountDisabledEmail({
to: metadata.user.email,
reason: metadata.reason,
});
}
}
}
With Priority
@Injectable()
@AccountStatusChangedHook({ priority: 1 })
export class AccountStatusEmailHook implements IAccountStatusChangedHook {
// Executes first
}
Default Priority: 100
Module Registration
import { Module } from '@nestjs/common';
import { AuthModule, NAuthHooksModule } from '@nauth-toolkit/nestjs';
import { AccountStatusNotificationHook } from './hooks/account-status.hook';
@Module({
imports: [
AuthModule.forRoot(authConfig),
NAuthHooksModule.forFeature([AccountStatusNotificationHook]),
],
})
export class CustomAuthModule {}
Related
- IAccountStatusChangedHook - Hook interface
- HookRegistryService - Hook registry
- Lifecycle Hooks Guide - Complete hooks overview