@10abdullahbutt/auth-module
Version:
A NestJS-style authentication module with JWT and role-based access control.
92 lines (70 loc) • 1.6 kB
Markdown
# @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
```bash
npm install @10abdullahbutt/auth-module
```
## Usage
### Import the Module
```typescript
import { Module } from '@nestjs/common';
import { AuthModule } from '@10abdullahbutt/auth-module';
export class AppModule {}
```
### Configure JWT
Override the `JwtModule.register` options in your main app for secret and expiration:
```typescript
import { JwtModule } from '@nestjs/jwt';
export class AppModule {}
```
### Protect Routes with JWT
```typescript
import { Controller, Get, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '@10abdullahbutt/auth-module';
export class ProfileController {
getProfile() {
// ...
}
}
```
### Role-based Access
```typescript
import { Controller, Get, UseGuards } from '@nestjs/common';
import { Roles, RolesGuard, JwtAuthGuard } from '@10abdullahbutt/auth-module';
export class AdminController {
getAdminData() {
// ...
}
}
```
## Testing
```bash
npm run test
```
## License
MIT