import { DynamicModule , Module , Provider } from '@nestjs/common' ; import { JwtModuleAsyncOptions , JwtModuleOptions , JwtOptionsFactory } from './interfaces/jwt-module-options.interface' ; import { JWT_MODULE_OPTIONS } from './jwt.constants' ; import { createJwtProvider } from './jwt.providers' ; import { JwtService } from './jwt.service' ; @ Module ( { providers : [ JwtService ] , exports : [ JwtService ] } ) export class JwtModule { static register ( options ) { return { module : JwtModule , providers : createJwtProvider ( options ) } ; } static registerAsync ( options ) { return { module : JwtModule , imports : options . imports || [ ] , providers : this . createAsyncProviders ( options ) } ; } private static createAsyncProviders ( options ) { if ( options . useExisting || options . useFactory ) { return [ this . createAsyncOptionsProvider ( options ) ] ; } return [ this . createAsyncOptionsProvider ( options ) , { provide : options . useClass , useClass : options . useClass } ] ; } private static createAsyncOptionsProvider ( options ) { if ( options . useFactory ) { return { provide : JWT_MODULE_OPTIONS , useFactory : options . useFactory , inject : options . inject || [ ] } ; } return { provide : JWT_MODULE_OPTIONS , useFactory : async ( optionsFactory ) => await optionsFactory . createJwtOptions ( ) , inject : [ options . useExisting || options . useClass ] } ; } }