#JwtModule inside dynamic module

7 messages · Page 1 of 1 (latest)

crude island
#

Hi, I want to create dynamic module which imports JwtModule in import array I added JwtModule, but module_options_token is provider of my dynamic module. How to pass options to register async?

    JwtModule.registerAsync({
      useFactory: (options: Options) => {
        return {
          secret: options.jwtSecret,
        };
      },
      inject: [MODULE_OPTIONS_TOKEN],
    }),
crude island
#

maybe there is a way to call useFactory manualy in registerAsync method?

strong swallow
#

Dynamic modules inside of dynamic modules hardly ever works well. What are you wanting to achieve with this nested dynamic module approach?

crude island
#

I want to achive package which gets config of JwtModule and other porperties and creates token which can be used later

#

with register it would work fine

  static register(options: typeof OPTIONS_TYPE): DynamicModule {
    const module = super.register(options);

    return {
      ...module,
      imports: [
        ...module.imports,
        JwtModule.registerAsync({
          useFactory: (options: Options) => {
            return {
              secret: options.jwtSecret,
            };
          },
          inject: [MODULE_OPTIONS_TOKEN],
        }),
      ],
    };
  }
strong swallow
crude island
#

thank you it worked for me 😁