@nestjs/passport
The official NestJS integration module for the Passport authentication middleware
Repository Health
Technical Analysis
@nestjs/passport is the official bridge between the NestJS framework and Passport, the widely-used Node.js authentication middleware with hundreds of strategy plugins (local, JWT, OAuth providers, SAML, and more). It wraps Passport’s callback-based strategy pattern in NestJS-idiomatic constructs — an AuthGuard and a PassportStrategy mixin — so authentication logic can be declared with decorators and dependency injection instead of manually wiring Express middleware.
The module itself is intentionally small: its job is to adapt Passport’s strategy.authenticate() lifecycle into NestJS’s guard and request-lifecycle model, letting any of Passport’s existing strategy packages be dropped into a Nest application with a few lines of glue code.
What You Get
AuthGuard('strategy-name')- a guard factory that authenticates incoming requests using any registered Passport strategyPassportStrategymixin - lets you define a custom strategy class as an injectable Nest provider that extends a Passport strategyPassportModule- registers Passport strategies with Nest’s module system, withregister()andregisterAsync()for static and dynamic configuration- Compatibility with the full Passport strategy ecosystem (local, JWT, Google, GitHub, SAML, and hundreds of others)
- TypeScript types for strategy options and validated user payloads
Common Use Cases
- Adding username/password (local strategy) login to a NestJS REST or GraphQL API
- Protecting routes with JWT bearer-token authentication via
passport-jwt - Wiring up third-party OAuth login (Google, GitHub, etc.) using existing Passport strategy packages
- Building a multi-strategy auth setup (e.g. local login plus JWT-protected API routes) in one Nest application
Under The Hood
Architecture The package is a thin adapter layer, roughly 428 lines across lib/: abstract.strategy.ts and passport.module.ts provide the module wiring, auth.guard.ts implements AuthGuard() as a Nest CanActivate guard that instantiates and invokes a named Passport strategy, and passport/ holds the strategy mixin machinery that lets a class extend both a Passport strategy and participate in Nest’s provider system. Tech Stack Built in TypeScript against @nestjs/common as a peer dependency and passport itself (supporting ^0.5.0 through ^0.7.0), with no other runtime dependencies — it deliberately stays a pass-through layer rather than reimplementing any authentication logic. Code Quality Tests live under test/with-register and test/without-register, explicitly covering both the static (register()) and dynamic module registration code paths, run via Vitest with coverage reporting (test:cov) — a structure that shows the two registration modes are treated as first-class, independently-tested behaviors rather than one being an afterthought. API Design The AuthGuard('name') factory and PassportStrategy mixin map directly onto NestJS’s existing guard and provider conventions, so a developer already familiar with Nest’s DI and decorators needs to learn almost nothing new to add authentication — the main friction is understanding Passport’s own strategy configuration, which this package doesn’t abstract away.
Used by 15 apps in this directory
Amplication
Developer Tools · AI Code Assistants · Automation
Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.
Bigcapital
Invoicing Finance
Self-hostable double-entry accounting platform with invoicing, inventory, multi-currency, and real-time financial reporting for small and medium businesses.
Cal.diy
Scheduling
The 100% MIT-licensed, community-driven scheduling platform — self-host your own booking infrastructure with no enterprise strings attached.
Docmost
Productivity · Note Taking · Collaboration
Self-hosted collaborative wiki and knowledge base with real-time editing, diagrams, AI assistance, and enterprise access controls — a modern alternative to Confluence and Notion.
Ghostfolio
Invoicing Finance
Track your stocks, ETFs, and crypto with a privacy-first, self-hostable wealth management platform built for data-driven investors.
Hexabot
AI Development · Automation
Build and run agentic workflows across channels with YAML, tools, and RAG
Hoppscotch
Developer Tools
A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.
Laudspeaker
Marketing · Automation
Open-source customer engagement platform for building visual, event-triggered messaging journeys across email, SMS, push, in-app, and webhooks.
NocoDB
No Code Platforms · Databases · Low Code Platforms
Turn any SQL database into a collaborative no-code spreadsheet with automatic REST APIs and real-time views.