@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/authenticationPeer 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-metadataWhat Each Dependency Does
| Package | Purpose |
|---|---|
@nestjs/passport | NestJS integration for Passport.js authentication strategies |
@nestjs/jwt | JWT token signing and verification |
passport | Core Passport.js authentication middleware |
passport-jwt | Passport strategy for JWT Bearer token extraction and validation |
passport-local | Passport strategy for username/password authentication |
class-validator | Decorator-based DTO validation (used for request body validation) |
class-transformer | Transform plain objects into class instances (required by class-validator) |
reflect-metadata | Polyfill 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-emitterThen 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-localCompatibility
| Dependency | Minimum Version |
|---|---|
| Node.js | 18.x |
| NestJS | 10.x |
| TypeScript | 5.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.
Introduction
Frontend-agnostic authentication backend for NestJS with complete auth lifecycle support, including registration, password reset, email verification, profile management, and two-factor authentication.
Quick Start
Set up a complete authentication system in your NestJS application in minutes with @nestbolt/authentication.