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-auth-kit

v1.4.6

Published

A modular and flexible authentication kit for NestJS with JWT, social login, OTP, and password reset.

Readme

🛡️ NestJS Auth Kit - NOT READY

A modular authentication kit for NestJS providing JWT authentication, OAuth2 social login (Google, Facebook, etc.), OTP verification, and password reset functionality.


🚀 Features

  • JWT-based authentication (Access & Refresh tokens)
  • OAuth2 social login (Google, Facebook, etc.)
  • OTP-based authentication (Email or SMS-based)
  • Password reset via OTP
  • Role-based access control (RBAC)
  • Modular and scalable architecture
  • Custom decorators for roles and authentication
  • Integration with NestJS Guards & Interceptors
  • Customizable authentication strategies
  • Configurable environment variables

📦 Installation

npm install nestjs-auth-kit

or with PNPM:

pnpm install nestjs-auth-kit

or with Yarn:

yarn add nestjs-auth-kit

🛠️ Setup & Usage

1️⃣ Import the AuthModule in app.module.ts


@Module({
    imports: [
        AuthModule.register({
            jwtSecret: process.env.JWT_SECRET,
            jwtExpiration: process.env.JWT_EXPIRATION || '1h',
            socialAuth: {
                google: {
                    clientId: process.env.GOOGLE_CLIENT_ID,
                    clientSecret: process.env.GOOGLE_CLIENT_SECRET,
                },
                facebook: {
                    clientId: process.env.FACEBOOK_CLIENT_ID,
                    clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
                },
            },
        }),
    ],
})
export class AppModule {}

2️⃣ Configure .env Variables

Make sure your environment variables are correctly set:

JWT_SECRET=your_jwt_secret
JWT_EXPIRATION=1h
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
FACEBOOK_CLIENT_ID=your_facebook_client_id
FACEBOOK_CLIENT_SECRET=your_facebook_client_secret
OTP_EXPIRATION=300  # OTP expiry time in seconds

3️⃣ Available Authentication Methods

🔹 JWT Authentication

Login and get a JWT token:

import { AuthService } from 'nestjs-auth-kit';

constructor(private authService: AuthService) {}

async login() {
  return this.authService.login({ email: '[email protected]', password: 'password' });
}

🔹 OAuth2 Social Login

Authenticate using Google:

import { SocialAuthService } from 'nestjs-auth-kit';

constructor(private socialAuthService: SocialAuthService) {}

async googleLogin(token: string) {
  return this.socialAuthService.validateGoogleUser(token);
}

🔹 OTP-based Authentication

Generate an OTP:

import { OtpService } from 'nestjs-auth-kit';

constructor(private otpService: OtpService) {}

async sendOtp(email: string) {
  return this.otpService.generateOtp(email);
}

Verify OTP:

async verifyOtp(email: string, otp: string) {
  return this.otpService.verifyOtp(email, otp);
}

🔹 Password Reset via OTP

import { ForgotPasswordService } from 'nestjs-auth-kit';

constructor(private forgotPasswordService: ForgotPasswordService) {}

async resetPassword(email: string, otp: string, newPassword: string) {
  return this.forgotPasswordService.resetPassword(email, otp, newPassword);
}

🔐 Role-Based Access Control (RBAC)

Use the @Roles() decorator to protect routes based on roles.

import { Controller, Get } from '@nestjs/common';
import { Roles } from 'nestjs-auth-kit';

@Controller('admin')
export class AdminController {
  @Get()
  @Roles('admin')
  getAdminData() {
    return { message: 'Admin data' };
  }
}

📜 API Endpoints

| Endpoint | Method | Description | |----------------------|--------|-------------| | /auth/login | POST | User login | | /auth/register | POST | User registration | | /auth/google | GET | Google OAuth login | | /auth/facebook | GET | Facebook OAuth login | | /auth/otp | POST | OTP generation | | /auth/otp/verify | POST | OTP verification | | /auth/password-reset | POST | Reset password via OTP | | /auth/me | GET | Get authenticated user info |


⚙️ Configuration Options

You can configure authentication options using AuthModule.register().

AuthModule.register({
  jwtSecret: process.env.JWT_SECRET,
  jwtExpiration: '1h',
  socialAuth: {
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    },
    facebook: {
      clientId: process.env.FACEBOOK_CLIENT_ID,
      clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
    },
  },
});

🏗️ Folder Structure

nestjs-auth-kit/
│── src/
│   ├── auth.module.ts
│   ├── auth.service.ts
│   ├── auth.controller.ts
│   ├── strategies/
│   │   ├── jwt.strategy.ts
│   │   ├── google.strategy.ts
│   │   ├── facebook.strategy.ts
│   ├── guards/
│   │   ├── jwt-auth.guard.ts
│   ├── decorators/
│   │   ├── roles.decorator.ts
│   ├── dto/
│   │   ├── login.dto.ts
│   │   ├── register.dto.ts
│   ├── interfaces/
│   │   ├── auth-options.interface.ts
│── package.json
│── index.ts

📄 License

MIT License © 2025 Galatex Solutions


🤝 Contribution Guidelines

  1. Fork the repository.
  2. Create a feature branch: git checkout -b feature-branch
  3. Commit your changes: git commit -m "Added new feature"
  4. Push to the branch: git push origin feature-branch
  5. Open a pull request.

📬 Contact & Support

For issues, questions, or suggestions, feel free to open an issue on GitHub.


🚀 NestJS Auth Kit is designed to simplify authentication in NestJS applications. Get started today! 🎯