JSPM

@10abdullahbutt/auth-module

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 1
    • Score
      100M100P100Q31648F
    • License MIT

    A NestJS-style authentication module with JWT and role-based access control.

    Package Exports

    • @10abdullahbutt/auth-module
    • @10abdullahbutt/auth-module/dist/index.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@10abdullahbutt/auth-module) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    @10abdullahbutt/auth-module

    A NestJS-style authentication module providing JWT authentication and role-based access control (RBAC).

    Features

    • JWT authentication guard
    • Role-based access control guard
    • Custom roles decorator
    • Easily pluggable into any NestJS application

    Installation

    npm install @10abdullahbutt/auth-module

    Usage

    Import the Module

    import { Module } from '@nestjs/common';
    import { AuthModule } from '@10abdullahbutt/auth-module';
    
    @Module({
      imports: [
        AuthModule,
      ],
    })
    export class AppModule {}

    Configure JWT

    Override the JwtModule.register options in your main app for secret and expiration:

    import { JwtModule } from '@nestjs/jwt';
    
    @Module({
      imports: [
        JwtModule.register({
          secret: process.env.JWT_SECRET,
          signOptions: { expiresIn: '1h' },
        }),
      ],
    })
    export class AppModule {}

    Protect Routes with JWT

    import { Controller, Get, UseGuards } from '@nestjs/common';
    import { JwtAuthGuard } from '@10abdullahbutt/auth-module';
    
    @Controller('profile')
    export class ProfileController {
      @UseGuards(JwtAuthGuard)
      @Get()
      getProfile() {
        // ...
      }
    }

    Role-based Access

    import { Controller, Get, UseGuards } from '@nestjs/common';
    import { Roles, RolesGuard, JwtAuthGuard } from '@10abdullahbutt/auth-module';
    
    @Controller('admin')
    @UseGuards(JwtAuthGuard, RolesGuard)
    export class AdminController {
      @Roles('admin')
      @Get()
      getAdminData() {
        // ...
      }
    }

    Testing

    npm run test

    License

    MIT