1.1.1 • Published 6 months ago

@soru/auth v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@soru/auth

A flexible authentication library for NestJS applications with role-based access control and permissions management.

Features

  • JWT-based authentication
  • Role-based access control (RBAC)
  • Granular permissions system
  • Easy integration with any NestJS project
  • Configurable token expiration
  • Refresh token support

Installation

npm install @soru/auth

Quick Start

  1. Import and configure the AuthModule in your app.module.ts:
import { AuthModule } from '@soru/auth';

@Module({
  imports: [
    AuthModule.register({
      jwtSecret: 'your-secret-key',
      jwtExpiresIn: '15m',
      refreshTokenExpiresIn: '7d',
    }),
  ],
})
export class AppModule {}
  1. Protect your routes with permissions:
import { RequirePermissions } from '@soru/auth';

@Controller('users')
export class UsersController {
  @RequirePermissions('users:create')
  @Post()
  createUser() {
    // Implementation
  }
}

API Reference

AuthModule

The main module that provides authentication functionality.

AuthModule.register(config: IAuthConfig)

IAuthConfig

Configuration options for the auth module:

interface IAuthConfig {
  jwtSecret: string;
  jwtExpiresIn?: string;
  refreshTokenExpiresIn?: string;
}

AuthService

Service for handling authentication operations:

class AuthService {
  generateTokens(user: IAuthUser): Promise<IAuthResponse>;
  validateToken(token: string): Promise<IAuthUser>;
}

Decorators

  • @RequirePermissions(...permissions: string[])

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

1.1.1

6 months ago

1.1.0

6 months ago

1.0.0

6 months ago