IAccountStatusChangedHook
Hook interface for executing actions after account status changes.
Overview
The IAccountStatusChangedHook interface enables reactions to account enable/disable events triggered by administrators.
The hook is non-blocking - errors are logged but do not affect the status change operation.
Interface
interface IAccountStatusChangedHook {
execute(metadata: AccountStatusChangedMetadata): Promise<void>;
}
Metadata
AccountStatusChangedMetadata
interface AccountStatusChangedMetadata {
user: IUser;
status: 'disabled' | 'enabled';
reason?: string;
performedBy?: string;
revokedSessions?: number;
clientInfo?: ClientInfo;
}
| Property | Type | Description |
|---|---|---|
user | IUser | User whose status changed |
status | 'disabled' | 'enabled' | New account status |
reason | string | Reason for status change |
performedBy | string | Admin who performed action (sub) |
revokedSessions | number | Sessions revoked (disable only) |
clientInfo | ClientInfo | IP, user agent, location |
When Hook Fires
- Admin disables user via
disableUser() - Admin enables user via
enableUser()
Example
import { IAccountStatusChangedHook, AccountStatusChangedMetadata } from '@nauth-toolkit/core';
export class AccountStatusNotificationHook implements IAccountStatusChangedHook {
async execute(metadata: AccountStatusChangedMetadata): Promise<void> {
if (metadata.status === 'disabled') {
await this.emailService.sendAccountDisabledEmail({
to: metadata.user.email,
reason: metadata.reason,
revokedSessions: metadata.revokedSessions,
});
}
}
}
Related
- HookRegistryService - Hook registration
- @AccountStatusChangedHook() - NestJS decorator
- Lifecycle Hooks Guide - Complete hooks overview