Skip to main content

@SessionsRevokedHook()

Package: @nauth-toolkit/nestjs Type: Class Decorator

Class decorator that automatically registers a provider as a sessions revoked hook. Executes after bulk session revocations. Non-blocking - errors are logged but don't affect revocation.

Overview​

The @SessionsRevokedHook() decorator enables automatic hook registration. Classes decorated with this decorator are discovered at module initialization and registered with the HookRegistryService.

Key Features:

  • Automatic hook discovery and registration
  • Full dependency injection support
  • Executes in NAuthHooksModule.forFeature() registration order
  • Non-blocking - errors don't affect revocation

Usage​

Basic Hook​

import { Injectable } from '@nestjs/common';
import {
SessionsRevokedHook,
ISessionsRevokedHook,
SessionsRevokedMetadata,
} from '@nauth-toolkit/nestjs';

@Injectable()
@SessionsRevokedHook()
export class SessionsRevokedAlertHook implements ISessionsRevokedHook {
constructor(private readonly emailService: EmailService) {}

async execute(metadata: SessionsRevokedMetadata): Promise<void> {
await this.emailService.sendSessionsRevokedEmail({
to: metadata.user.email,
revokedCount: metadata.revokedCount,
reason: metadata.reason,
});
}
}

Module Registration​

import { Module } from '@nestjs/common';
import { AuthModule, NAuthHooksModule } from '@nauth-toolkit/nestjs';
import { SessionsRevokedAlertHook } from './hooks/sessions-revoked.hook';

@Module({
imports: [
AuthModule.forRoot(authConfig),
NAuthHooksModule.forFeature([SessionsRevokedAlertHook]),
],
})
export class CustomAuthModule {}