NestJS Profiler
API Reference

nest-profiler-auth

Types and API of the auth & security collector.

AuthCollectorModuleOptions

Options passed to AuthCollectorModule.forRoot().

Prop

Type

SecurityContext

The data structure populated by the auth collector and stored in profile.security. Defined in @eleven-labs/nest-profiler.

interface SecurityContext {
  isAuthenticated: boolean;
  user?: Record<string, unknown>; // request.user, with masked fields
  roles?: string[]; // user.roles or user.role (normalized)
  jwtClaims?: Record<string, unknown>; // decoded JWT payload (no verification)
}

See SecurityContext in the core package reference.

Automatic masking

Fields in user whose name matches the pattern /password|secret|key|token|credential|api_key|apikey/i are replaced with ***. Additional fields can be specified via maskUserFields.

Public exports

import { AuthCollectorModule } from '@eleven-labs/nest-profiler-auth';
import { AuthCollector } from '@eleven-labs/nest-profiler-auth';

import { AUTH_COLLECTOR_OPTIONS } from '@eleven-labs/nest-profiler-auth';

import type {
  AuthCollectorModuleOptions,
  AuthCollectorModuleAsyncOptions,
  AuthBadgeMode,
} from '@eleven-labs/nest-profiler-auth';

Setup

profiling/profiling.module.ts
import { Module } from '@nestjs/common';
import { ProfilerModule } from '@eleven-labs/nest-profiler';
import { AuthCollectorModule } from '@eleven-labs/nest-profiler-auth';

@Module({
  imports: [
    ProfilerModule.forRoot({ isGlobal: true }),
    AuthCollectorModule.forRoot({ maskUserFields: ['password', 'refreshToken'] }),
  ],
})
export class ProfilingModule {}

ProfilingModule is the dev-only bundle loaded by main-dev.ts — see Enabling and disabling the profiler. If the profiler is installed as a production dependency behind the runtime gate, wrap the same call in ConditionalModule.registerWhen(..., isProfilerEnabled).

Prerequisite: A guard or middleware that sets request.user (Passport, custom JWT guard, etc.), which stays in your production modules. The collector reads request.user and the Authorization header from the per-request CLS context.

Async setup

Drive the options from ConfigService (or any provider) with forRootAsync(), added to the dev-only bundle's imports in place of forRoot(). It resolves option values only — for the enabled flag and when to prefer forRoot, see Enabling and disabling the profiler.

import { ConfigService } from '@nestjs/config';
import { AuthCollectorModule } from '@eleven-labs/nest-profiler-auth';

AuthCollectorModule.forRootAsync({
  inject: [ConfigService],
  useFactory: (config: ConfigService) => ({
    maskUserFields: config.get<string[]>('profiler.maskUserFields') ?? ['password', 'refreshToken'],
  }),
});
Powered & maintained by

On this page