UNPKG

@10abdullahbutt/auth-module

Version:

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

26 lines (24 loc) 885 B
import { Module } from '@nestjs/common'; import { JwtModule } from '@nestjs/jwt'; import { PassportModule } from '@nestjs/passport'; import { JwtStrategy } from './strategies/jwt.strategy'; import { JwtAuthGuard } from './guards/jwt-auth.guard'; import { RolesGuard } from './guards/roles.guard'; import { ConfigModule, ConfigService } from '@nestjs/config'; @Module({ imports: [ ConfigModule, PassportModule, JwtModule.registerAsync({ imports: [ConfigModule], inject: [ConfigService], useFactory: async (configService: ConfigService) => ({ secret: configService.get<string>('JWT_SECRET', 'secret'), signOptions: { expiresIn: configService.get<string>('JWT_EXPIRES_IN', '1h') }, }), }), ], providers: [JwtStrategy, JwtAuthGuard, RolesGuard], exports: [JwtModule, JwtAuthGuard, RolesGuard], }) export class AuthModule {}