@nestjs/passport

The official NestJS integration module for the Passport authentication middleware

Library
npm
v12.0.0
561 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
98%
Other

Novu

Developer Tools

40,195

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.

View details
93
Repo Health
80
Technical
64
Dependency
Built with
TypeScript 98%
Updated 6 days ago
TypeScript
96%
Other

Refly

AI Development · Automation · No Code Platforms

7,537

Build deterministic, versioned agent skills from natural language—run them anywhere from Claude Code to Slack.

View details
68
Repo Health
76
Technical
63
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
TypeScript
97%
AGPL 3.0

Swetrix

Analytics

1,213

Privacy-first, cookieless web analytics with error tracking, session replays, and performance monitoring — self-host or use Cloud.

View details
87
Repo Health
71
Technical
66
Dependency
Built with
TypeScript 97%
Updated 1 weeks ago
TypeScript
99%
Other

Teable

Databases · No Code Platforms

21,920

A no-code PostgreSQL database with spreadsheet UX, real-time collaboration, and native AI agents — built for teams that outgrow Airtable.

View details
78
Repo Health
76
Technical
62
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
HTML
68%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,123

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.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
HTML 68%
JavaScript 20%
Updated 6 days ago
TypeScript
84%
Other

twenty

CRM

59,615

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 84%
MDX 14%
Updated 1 weeks 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