NestboltNestbolt

@nestbolt/authentication

Installation

Install @nestbolt/authentication and its peer dependencies in your NestJS application.

Install the Package

Install @nestbolt/authentication using your preferred package manager:

# pnpm
pnpm add @nestbolt/authentication

# npm
npm install @nestbolt/authentication

# yarn
yarn add @nestbolt/authentication

Peer Dependencies

The package requires several peer dependencies that are not bundled. Install them alongside the main package:

# pnpm
pnpm add @nestjs/passport @nestjs/jwt passport passport-jwt passport-local class-validator class-transformer reflect-metadata

# npm
npm install @nestjs/passport @nestjs/jwt passport passport-jwt passport-local class-validator class-transformer reflect-metadata

# yarn
yarn add @nestjs/passport @nestjs/jwt passport passport-jwt passport-local class-validator class-transformer reflect-metadata

What Each Dependency Does

PackagePurpose
@nestjs/passportNestJS integration for Passport.js authentication strategies
@nestjs/jwtJWT token signing and verification
passportCore Passport.js authentication middleware
passport-jwtPassport strategy for JWT Bearer token extraction and validation
passport-localPassport strategy for username/password authentication
class-validatorDecorator-based DTO validation (used for request body validation)
class-transformerTransform plain objects into class instances (required by class-validator)
reflect-metadataPolyfill for the Metadata Reflection API (required by NestJS decorators)

Optional Dependencies

Event Emitter

If you want to subscribe to authentication lifecycle events (login, logout, registration, password reset, etc.), install the NestJS event emitter:

# pnpm
pnpm add @nestjs/event-emitter

# npm
npm install @nestjs/event-emitter

# yarn
yarn add @nestjs/event-emitter

Then register the EventEmitterModule in your application module:

import { Module } from "@nestjs/common";
import { EventEmitterModule } from "@nestjs/event-emitter";
import { AuthenticationModule, Feature } from "@nestbolt/authentication";

@Module({
  imports: [
    EventEmitterModule.forRoot(),
    AuthenticationModule.forRoot({
      // ... your configuration
    }),
  ],
})
export class AppModule {}

When EventEmitterModule is registered, the authentication module automatically detects it and emits events. When it is not present, the module operates normally without emitting any events.

TypeScript Types

If you are using TypeScript and encounter missing type definitions, install the type packages for Passport:

# pnpm
pnpm add -D @types/passport-jwt @types/passport-local

# npm
npm install -D @types/passport-jwt @types/passport-local

# yarn
yarn add -D @types/passport-jwt @types/passport-local

Compatibility

DependencyMinimum Version
Node.js18.x
NestJS10.x
TypeScript5.0+

The package is framework-agnostic on the frontend side. It works with any HTTP client -- React, Vue, Angular, mobile apps, or plain fetch/curl.

Validation Pipe

The package uses class-validator decorators on its DTOs. To ensure request validation works correctly, you must enable the global ValidationPipe in your NestJS application:

import { ValidationPipe } from "@nestjs/common";
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  app.useGlobalPipes(
    new ValidationPipe({
      whitelist: true,
      forbidNonWhitelisted: true,
      transform: true,
    }),
  );

  await app.listen(3000);
}
bootstrap();

The whitelist option strips unknown properties from request bodies, forbidNonWhitelisted throws an error if unknown properties are sent, and transform automatically transforms payloads into DTO class instances.

Next Steps

Once you have installed the package and its dependencies, proceed to the Quick Start guide to set up your first working authentication system.