@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
Novu
Developer Tools
Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.
Refly
AI Development · Automation · No Code Platforms
Build deterministic, versioned agent skills from natural language—run them anywhere from Claude Code to Slack.
Swetrix
Analytics
Privacy-first, cookieless web analytics with error tracking, session replays, and performance monitoring — self-host or use Cloud.
Teable
Databases · No Code Platforms
A no-code PostgreSQL database with spreadsheet UX, real-time collaboration, and native AI agents — built for teams that outgrow Airtable.
ToolJet
AI Agents · Low Code Platforms · No Code Platforms
Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.
twenty
CRM
The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.