To allow for the registration of multiple variants of the same service, you're going to need to use a custom provider and wrapper module around the JwtModule
. It would probably look something like this:
@Module({
imports: [JwtModule.register({
secret: secret1,
signOptions: { expiresIn: '60s' },
})],
providers: [{
provide: 'JwtSecret1Service',
useExisting: JwtService,
}],
exports: ['JwtSecret1Service'],
})
export class JwtSecret1Module {}
Now you can use @Inject('JwtSecret1Service')
to use this specific configuration so long as JwtSecret1Module
has been added to the imports
of the consuming module. You can do this with as many variants of the JwtService
as you want, and each one will hold it's own configuration
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…