@UserProfileUpdatedHook()
Package: @nauth-toolkit/nestjs
Type: Class Decorator
Marks a provider as a user profile updated hook for automatic registration with NAuthHooksModule.
import { UserProfileUpdatedHook } from '@nauth-toolkit/nestjs';
Overview
The @UserProfileUpdatedHook() decorator automatically registers a class with the HookRegistryService when used with NAuthHooksModule.forFeature(). The decorated class must implement IUserProfileUpdatedHook.
note
Requires NAuthHooksModule.forFeature() to be imported in your module.
Signature
function UserProfileUpdatedHook(options?: HookDecoratorOptions): ClassDecorator;
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
options | HookDecoratorOptions | No | Configuration options (priority) |
HookDecoratorOptions
| Property | Type | Required | Description |
|---|---|---|---|
priority | number | No | Execution priority (lower = earlier). Default: 100 |
Example
import { Injectable } from '@nestjs/common';
import { UserProfileUpdatedHook, IUserProfileUpdatedHook, UserProfileUpdatedMetadata } from '@nauth-toolkit/nestjs';
@Injectable()
@UserProfileUpdatedHook({ priority: 1 })
export class CrmSyncHook implements IUserProfileUpdatedHook {
constructor(private readonly crmService: CrmService) {}
async execute(metadata: UserProfileUpdatedMetadata): Promise<void> {
// Sync email changes to CRM
const emailChange = metadata.changedFields.find((f) => f.fieldName === 'email');
if (emailChange) {
await this.crmService.updateContact(metadata.user.sub, {
email: emailChange.newValue as string,
});
}
}
}
Registration
Register the hook using NAuthHooksModule.forFeature():
import { Module } from '@nestjs/common';
import { AuthModule, NAuthHooksModule } from '@nauth-toolkit/nestjs';
import { CrmSyncHook } from './hooks/crm-sync.hook';
@Module({
imports: [AuthModule.forRoot(authConfig), NAuthHooksModule.forFeature([CrmSyncHook])],
})
export class AuthModule {}
Hook Execution
- Executes after user profile attributes change
- Runs in priority order (lower priority number = earlier execution)
- Non-blocking - errors are logged but don't affect updates
- All hooks execute regardless of errors
Related APIs
- IUserProfileUpdatedHook - Hook interface
- NAuthHooksModule - Hook registration module
- HookRegistryService - Hook registry