IPasswordChangedHook
Hook interface for executing actions after password changes.
Overview
The IPasswordChangedHook interface enables reactions to password change events. This includes user-initiated changes, admin password resets, and password recovery completions.
The hook is non-blocking - errors are logged but do not affect the password change operation.
Interface
interface IPasswordChangedHook {
execute(metadata: PasswordChangedMetadata): Promise<void>;
}
Metadata
PasswordChangedMetadata
interface PasswordChangedMetadata {
user: IUser;
changedBy: 'user' | 'admin' | 'reset';
sessionsRevoked?: number;
clientInfo?: ClientInfo;
}
| Property | Type | Description |
|---|---|---|
user | IUser | User whose password was changed |
changedBy | 'user' | 'admin' | 'reset' | How password was changed |
sessionsRevoked | number | Number of sessions revoked |
clientInfo | ClientInfo | IP, user agent, location |
When Hook Fires
- User changes own password via
changePassword() - Admin sets new password via
adminSetPassword() - Password reset completed via
confirmPasswordReset()
Example
import { IPasswordChangedHook, PasswordChangedMetadata } from '@nauth-toolkit/core';
export class PasswordChangedEmailHook implements IPasswordChangedHook {
async execute(metadata: PasswordChangedMetadata): Promise<void> {
await this.emailService.sendPasswordChangedAlert({
to: metadata.user.email,
changedBy: metadata.changedBy,
sessionsRevoked: metadata.sessionsRevoked || 0,
});
}
}
Related
- HookRegistryService - Hook registration
- @PasswordChangedHook() - NestJS decorator
- Lifecycle Hooks Guide - Complete hooks overview