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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@miinded/nestjs-auth-jwt

v1.0.1

Published

Production-ready NestJS module for JWT authentication with passport integration. Features access tokens, refresh tokens, and full TypeScript support.

Downloads

19

Readme

@miinded/nestjs-auth-jwt

npm version License: MIT

Production-ready NestJS module for JWT authentication with Passport integration. Features access tokens, refresh tokens, built-in middleware, and full TypeScript support.

Features

  • 🔐 Access Token — JWT authentication via Passport strategy
  • 🔄 Refresh Token — Built-in refresh token strategy and GET /auth/refreshtoken endpoint
  • 🛡️ Guard & MiddlewareJwtRefreshTokenGuard and JwtMiddleware ready to use
  • 🔌 Custom User Service — Inject your own user lookup logic via IJwtAuth
  • ⏱️ Auto expiry — Defaults to expiresIn: 5m if not specified
  • 📝 Full TypeScript — Complete type definitions for excellent DX
  • Well Tested — Unit and integration tests with 80%+ coverage

Installation

npm install @miinded/nestjs-auth-jwt
# or
pnpm add @miinded/nestjs-auth-jwt
# or
yarn add @miinded/nestjs-auth-jwt

Quick Start

1. Implement the IJwtAuth interface

import { Injectable } from '@nestjs/common';
import { IJwtAuth } from '@miinded/nestjs-auth-jwt';

@Injectable()
export class UserService implements IJwtAuth {
  async getOneUserByJwt(payload: { sub: string }) {
    return this.usersRepository.findOne({ where: { id: payload.sub } });
  }

  async getOneUserByRefreshToken(payload: { sub: string }) {
    return this.usersRepository.findOne({ where: { id: payload.sub } });
  }
}

2. Register the module

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AuthJwtModule } from '@miinded/nestjs-auth-jwt';
import { UserService } from './user.service';

@Module({
  imports: [
    ConfigModule.forRoot(),
    AuthJwtModule.registerAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      userService: UserService,
      useFactory: (config: ConfigService) => ({
        token: {
          secret: config.getOrThrow('JWT_SECRET'),
          signOptions: { expiresIn: '15m' },
        },
        refreshToken: {
          secret: config.getOrThrow('JWT_REFRESH_SECRET'),
          signOptions: { expiresIn: '7d' },
        },
      }),
    }),
  ],
})
export class AppModule {}

This automatically registers GET /auth/refreshtoken (protected by JwtRefreshTokenGuard).

3. Protect routes with a Guard

import { Controller, Get, UseGuards, Req } from '@nestjs/common';
import { AuthGuard } from '@miinded/nestjs-auth-jwt';

@Controller('profile')
export class ProfileController {
  @UseGuards(AuthGuard('jwt'))
  @Get()
  getProfile(@Req() req: { user: unknown }) {
    return req.user;
  }
}

4. Protect routes with Middleware

import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import { JwtMiddleware } from '@miinded/nestjs-auth-jwt';

@Module({})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(JwtMiddleware).forRoutes('*');
  }
}

Usage Example

import { Injectable } from '@nestjs/common';
import { IJwtAuth } from '@miinded/nestjs-auth-jwt';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { User } from './user.entity';

@Injectable()
export class UserService implements IJwtAuth {
  constructor(
    @InjectRepository(User)
    private readonly users: Repository<User>,
  ) {}

  async getOneUserByJwt(payload: { sub: string }) {
    return this.users.findOne({ where: { id: payload.sub } });
  }

  async getOneUserByRefreshToken(payload: { sub: string }) {
    return this.users.findOne({ where: { id: payload.sub } });
  }
}

API Reference

AuthJwtModule.registerAsync(options)

| Option | Type | Required | Description | | ------------- | ------------------------ | -------- | ----------------------------------- | | userService | Type<IJwtAuth> | ✅ | Class implementing IJwtAuth | | useFactory | (...args) => JWTConfig | ❌ | Factory returning JWT config | | inject | any[] | ❌ | Dependencies to inject into factory | | imports | Module[] | ❌ | Modules to import |

JWTConfig

| Option | Type | Description | | -------------- | ------------------ | --------------------------------------------------------- | | token | JwtModuleOptions | Access token config (secret, signOptions.expiresIn…) | | refreshToken | JwtModuleOptions | Refresh token config (secret, signOptions.expiresIn…) |

If token.signOptions.expiresIn is not set, it defaults to 5m.

IJwtAuth interface

| Method | Signature | Description | | -------------------------- | ------------------------------------------- | --------------------------------------- | | getOneUserByJwt | (payload: JwtPayload) => Promise<unknown> | Resolve user from access token payload | | getOneUserByRefreshToken | (payload: JwtPayload) => Promise<unknown> | Resolve user from refresh token payload |

Exports

| Symbol | Description | | ------------------------- | ------------------------------------------- | | AuthJwtModule | Main module | | JwtMiddleware | Middleware for JWT authentication | | JwtRefreshTokenGuard | Guard for refresh token routes | | JwtStrategy | Passport JWT access token strategy | | JwtRefreshTokenStrategy | Passport refresh token strategy | | IJwtAuth | Interface to implement in your user service | | JwtService | Re-exported from @nestjs/jwt | | PassportModule | Re-exported from @nestjs/passport | | AuthGuard | Re-exported from @nestjs/passport | | PassportStrategy | Re-exported from @nestjs/passport | | JWT_USER_SERVICE | Injection token for user service | | JWT_MODULE_OPTIONS | Injection token for module options |

License

MIT © Miinded