@nestjs/passport

The official NestJS integration module for the Passport authentication middleware

Library
npm
v12.0.0
559 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
83 /100 Excellent
Development Activity 96
Maintenance 84
Community 64
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
75 /100 Good
Architecture 78
Code Quality 82
Innovation 60
Learning Curve 80

@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 strategy
  • PassportStrategy mixin - lets you define a custom strategy class as an injectable Nest provider that extends a Passport strategy
  • PassportModule - registers Passport strategies with Nest’s module system, with register() and registerAsync() 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

TypeScript
96%
Other

Amplication

AI Code Assistants · Automation · Developer Tools

16,015

Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.

View details
58
Repo Health
84
Technical
60
Dependency
Built with
TypeScript 96%
Updated 3 months ago
TypeScript
97%
AGPL 3.0

Bigcapital

Invoicing Finance

3,916

Self-hostable double-entry accounting platform with invoicing, inventory, multi-currency, and real-time financial reporting for small and medium businesses.

View details
90
Repo Health
77
Technical
61
Dependency
Built with
TypeScript 97%
Updated 6 days ago
TypeScript
96%
Other

Cal.diy

Scheduling

48,697

The 100% MIT-licensed, community-driven scheduling platform — self-host your own booking infrastructure with no enterprise strings attached.

View details
91
Repo Health
86
Technical
65
Dependency
Built with
TypeScript 96%
Updated 6 days ago
TypeScript
95%
AGPL 3.0

Docmost

CMS · Collaboration · Note Taking

21,801

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.

View details
89
Repo Health
70
Technical
69
Dependency
Built with
TypeScript 95%
Updated 5 days ago
TypeScript
76%
AGPL 3.0

Ghostfolio

Invoicing Finance

9,367

Track your stocks, ETFs, and crypto with a privacy-first, self-hostable wealth management platform built for data-driven investors.

View details
93
Repo Health
79
Technical
67
Dependency
Built with
TypeScript 76%
HTML 21%
Updated 5 days ago
TypeScript
98%
Other

Hexabot

AI Development · Automation

1,260

Build and run agentic workflows across channels with YAML, tools, and RAG

View details
78
Repo Health
76
Technical
65
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
TypeScript
67%
MIT

Hoppscotch

Developer Tools

80,529

A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.

View details
91
Repo Health
83
Technical
65
Dependency
Built with
TypeScript 67%
Vue 25%
Updated 6 days ago
TypeScript
94%
AGPL 3.0

Laudspeaker

Automation · Marketing

2,626

Open-source customer engagement platform for building visual, event-triggered messaging journeys across email, SMS, push, in-app, and webhooks.

View details
51
Repo Health
66
Technical
62
Dependency
Built with
TypeScript 94%
Updated 2 months ago
TypeScript
65%
Other

NocoDB

Databases · Low Code Platforms · No Code Platforms

65,098

Turn any SQL database into a collaborative no-code spreadsheet with automatic REST APIs and real-time views.

View details
90
Repo Health
77
Technical
62
Dependency
Built with
TypeScript 65%
Vue 30%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers