Skip to main content

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;
}
PropertyTypeDescription
userIUserUser whose password was changed
changedBy'user' | 'admin' | 'reset'How password was changed
sessionsRevokednumberNumber of sessions revoked
clientInfoClientInfoIP, 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,
});
}
}