Skip to main content

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;
}
PropertyTypeDescription
userIUserUser whose status changed
status'disabled' | 'enabled'New account status
reasonstringReason for status change
performedBystringAdmin who performed action (sub)
revokedSessionsnumberSessions revoked (disable only)
clientInfoClientInfoIP, 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,
});
}
}
}