Skip to main content

IUserProfileUpdatedHook

Hook interface for executing actions after user profile attribute changes.

Overview

The IUserProfileUpdatedHook interface enables reactions to user profile attribute changes. This includes core attributes (firstName, lastName, username, email, phone, metadata) and verification status (isEmailVerified, isPhoneVerified).

The hook is non-blocking - errors are logged but do not affect the update operation.

Interface

interface IUserProfileUpdatedHook {
execute(metadata: UserProfileUpdatedMetadata): Promise<void>;
}

Metadata

UserProfileUpdatedMetadata

interface UserProfileUpdatedMetadata {
user: IUser;
changedFields: ChangedField[];
updateSource: UserProfileUpdateSource;
performedBy?: string;
clientInfo?: ClientInfo;
}
PropertyTypeDescription
userIUserUpdated user entity (after change)
changedFieldsChangedField[]Fields that changed with old/new values
updateSourceUserProfileUpdateSourceWhat triggered the update
performedBystringAdmin user sub (admin_action source only)
clientInfoClientInfoIP, user agent, location

ChangedField

interface ChangedField {
fieldName: string;
oldValue: unknown;
newValue: unknown;
}
PropertyTypeDescription
fieldNamestringName of the field
oldValueunknownPrevious value
newValueunknownNew value

UserProfileUpdateSource

type UserProfileUpdateSource =
| 'user_request'
| 'admin_action'
| 'email_verification'
| 'phone_verification';

When Hook Fires

Included Changes:

  • Core attributes: firstName, lastName, username, email, phone, metadata
  • Verification status: isEmailVerified, isPhoneVerified

Excluded Changes:

  • Password changes (use IPasswordChangedHook)
  • Account lock/unlock (use IAccountLockedHook)
  • MFA changes (use IMFADeviceRemovedHook, IMFAFirstEnabledHook, IMFAMethodAddedHook)

Example

import { IUserProfileUpdatedHook, UserProfileUpdatedMetadata } from '@nauth-toolkit/core';

export class CrmSyncHook implements IUserProfileUpdatedHook {
async execute(metadata: UserProfileUpdatedMetadata): Promise<void> {
const emailChange = metadata.changedFields.find(f => f.fieldName === 'email');
if (emailChange) {
await this.crmService.updateContact(metadata.user.sub, {
email: emailChange.newValue as string
});
}
}
}