Repo of the Day
jajaperson/nestjs-auth0
Published: Sep 7, 2022
Open repository ↗Nest Auth0 via Passwort - Example App
Summary
jajaperson/nestjs-auth0 is a NestJS template that wires up Auth0 authentication using Passport. It combines jwks-rsa, passport-jwt, and @nestjs/passport so a Nest app can verify JWT bearer tokens issued by Auth0 with minimal boilerplate. The repository is positioned as a starting point engineers can clone and adapt rather than a drop-in library.
What it is useful for
This template fits engineers who already have, or are starting, a NestJS service and need to lock down routes with Auth0-issued JWTs. Concrete uses include:
- Bootstrapping a new NestJS API that should accept Auth0 access tokens as its primary auth method.
- Replacing ad-hoc JWT verification code with a strategy that fetches signing keys from Auth0's JWKS endpoint, so the app does not hardcode a shared secret and can rotate keys without redeploying.
- Studying a working example of
@UseGuards(AuthGuard())on a Nest controller, useful for engineers who learn best from a runnable reference. - Standing up integration tests that exercise real token-validation code paths, since the project ships with both unit and e2e Jest scripts.
How engineers can use it
The README documents a straightforward setup:
- Clone with
git clone --depth 1 https://github.com/jajaperson/nestjs-auth0.gitand runnpm install. - Create a
.envfile (a.env.exampleis included) withAUTH0_DOMAIN,AUTH0_CLIENT_ID,AUTH0_CLIENT_SECRET, andAUTH0_AUDIENCE. These values are read via@nestjs/config. - Run with
npm run start:devfor watch mode,npm run start:prodfor production, andnpm run testornpm run test:e2efor tests.
The interesting code lives in src/auth/. jwt.strategy.ts builds the JwtStrategy: it uses jwks-rsa to pull Auth0's public keys and passport-jwt to verify incoming bearer tokens, then runs a validate step that checks required scopes against the decoded JwtPayload. auth.module.ts exports both PassportModule and JwtStrategy and registers the strategy as the default, so controllers in src/app.controller.ts only need @UseGuards(AuthGuard()) to be protected.
Before adopting it, engineers should note two things from the README: the package.json fields (repository, homepage, bugs, description) are template boilerplate meant to be cleaned up after forking, and the project is described as a template rather than a published library. The README also does not document a full walkthrough of running the app against a live Auth0 tenant, so for tenant configuration and callback URLs the linked Nest and Auth0 docs are the next reference.