npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

nestjs-auth0-module

v1.0.7

Published

A reusable NestJS authentication module for Auth0.

Downloads

24

Readme

Overview

This package is a NestJS Auth Module to help facilitate integration with Auth0. It includes some other features such as Guards for Auth and Permissions as well as an in-build @Permissions decorator to extract permissions/access scopes.

If you would like to see new stuff added to this package, feel free to reach out to me either via email ([email protected]) or by opening an issue on the Github repository!

Installation

Installation is pretty straightforward. Just install it using npm or your favourite package manager.

npm i nestjs-auth0-module

Usage

I won't go into details on how to use Auth0 since their documentation is good enough as is. To use this package, you just need to get your audience (your created api) and issuer url (your tenant url) variables.

Your .env file should look something like this:

# Auth0 config
AUTH0_AUDIENCE=https://your-api.com
AUTH0_ISSUER_URL=https://your-tenant-url.us.auth0.com/

AuthModule

You can import this on your app.module.ts file or on another module. You need to pass the audience and issuer url params to the AuthModule to configure it using the forRoot method. To use environment variables, you would need either the @nestjs/config or the dotenv packages as you can see in the example below:

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from 'nestjs-auth0-module';
import { ConfigModule } from '@nestjs/config';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    AuthModule.forRoot({
      audience: process.env.AUTH0_AUDIENCE,
      issuer: process.env.AUTH0_ISSUER_URL,
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

JwtAuthGuard

The AuthModule by itself doesn't do any magic. We need this little fellow here together with the @UseGuards decorator that comes with the @nestjs/common package.

You can use it both above the controller to affect all methods or just on the specific route you need authentication.

import { Controller, Get, UseGuards } from '@nestjs/common';
import { AppService } from './app.service';
import { JwtAuthGuard } from 'nestjs-auth0-module';

@UseGuards(JwtAuthGuard)
@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  getHello(): string {
    return this.appService.getHello();
  }
}

In case the user does not pass a valid Auth0 token using the Bearer token format, it will throw a 401 error.

@Permissions and PermissionsGuard

In tandem with the JwtAuthGuard, we can also call our PermissionsGuard to validate the permissions/access scopes from the access token and see if they include the required permission(s) on the @Permissions decorator.

import { Controller, Get, UseGuards } from '@nestjs/common';
import { AppService } from './app.service';
import {
  JwtAuthGuard,
  Permissions,
  PermissionsGuard,
} from 'nestjs-auth0-module';

@UseGuards(JwtAuthGuard, PermissionsGuard)
@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Permissions('read:all')
  @Get()
  getHello(): string {
    return this.appService.getHello();
  }
}

In case the user does not have the required permission(s), it will throw a 403 error.

Multiple permissions

Just add them to the decorator like the example below and the guard will validate them all.

@Permissions('read:all', 'read:hello')
@Get()
getHello(): string {
return this.appService.getHello();
}

JwtStrategy

In most cases, you won't need this. It is only exported because you might want to extend it for more specific cases that aren't currently covered by this package. Feel free to reach out to me if you want to see more customization regarding this!

Demo repository

If you want, you can check out my demo repository so you can see the integration with the package by yourself. It has just the base NestJS dependencies and the nestjs-auth0-module package.

License

This package is MIT licensed