UNPKG

nestjs-auth-kit

Version:

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

46 lines (44 loc) 1.72 kB
import { DynamicModule, Module } from '@nestjs/common'; import { AuthService } from './auth.service'; import { AuthController } from './auth.controller'; import { JwtModule } from '@nestjs/jwt'; import { PassportModule } from '@nestjs/passport'; import { JwtStrategy } from './strategies/jwt.strategy'; import { GoogleStrategy } from './strategies/google.strategy'; import { FacebookStrategy } from './strategies/facebook.strategy'; import { AuthOptions } from './interfaces/auth-options.interface'; import { OtpService } from './services/otp.service'; import { ForgotPasswordService } from './services/forgot-password.service'; import { TypeOrmModule } from '@nestjs/typeorm'; import { OtpEntity } from './entities/otp.entity'; import { User } from './entities/user.entity'; @Module({}) export class AuthModule { static register(options: AuthOptions): DynamicModule { return { module: AuthModule, imports: [ TypeOrmModule.forFeature([OtpEntity, User]), PassportModule.register({ defaultStrategy: 'jwt' }), JwtModule.register({ secret: options.jwtSecret, signOptions: { expiresIn: options.jwtExpiration }, }), ], providers: [ AuthService, OtpService, ForgotPasswordService, JwtStrategy, GoogleStrategy, FacebookStrategy, { provide: 'AUTH_OPTIONS', useValue: options, }, ], controllers: [AuthController], exports: [AuthService], }; } }