I like to implement more than one named passport-JWT strategy, each with its own secret
. Is there any way it can be implemented?
From what I can understand from the documentation, only one secret can be registered during module initialization:
@Module({
imports: [
UsersModule,
PassportModule,
JwtModule.register({
secret: jwtConstants.secret,
signOptions: { expiresIn: '60s' },
}),
],
providers: [AuthService, LocalStrategy],
exports: [AuthService, JwtModule],
})
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:Now you can use
@Inject('JwtSecret1Service')
to use this specific configuration so long asJwtSecret1Module
has been added to theimports
of the consuming module. You can do this with as many variants of theJwtService
as you want, and each one will hold it's own configuration