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.

Not in Main Barrel Export

SessionsRevokedHook is not exported from the @nauth-toolkit/nestjs main entry point. Register this hook manually using HookRegistryService instead of the decorator pattern.

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
  • Priority-based execution ordering
  • 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,
});
}
}

With Priority

@Injectable()
@SessionsRevokedHook({ priority: 1 })
export class SessionsRevokedEmailHook implements ISessionsRevokedHook {
// Executes first
}

Default Priority: 100

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 {}