• p

    porcx

    6 months ago
    Hello. I am new to supertokens. I am using nest js with supertokens. As documentation auth.module has static function
    static forRoot({ connectionURI, apiKey, appInfo }: AuthModuleConfig): DynamicModule {
          return {
            providers: [
              {
                useValue: {
                  appInfo,
                  connectionURI,
                  apiKey,
                },
                provide: ConfigInjectionToken,
              },
            ],
            exports: [],
            imports: [],
            module: AuthModule,
          };
        }
    And Then I have used this method to to app.module something like this
    imports: [
        AuthModule.forRoot({
          connectionURI: process.env.AUTH_CONNECTION_URI,
          appInfo: {
            appName: "canopy",
            apiDomain: process.env.API_DOMAIN,
            websiteDomain: process.env.WEBSITE_DOMAIN,
            apiBasePath: "/auth/",
            websiteBasePath: "/",
          },
        }),
        ConfigModule.forRoot({
          isGlobal: true,
          load: [config],
        })
      ],
    My question is how can i use configService to get the env values in AuthModule.forRoot function ?
  • r

    rp

    6 months ago
    @User can help out with this.
  • p

    porcellus

    6 months ago
    Hi @User, what
    configService
    are you referring to?
  • p

    porcellus

    6 months ago
    If you want to access those values in another service you can take a look at
    supertokens.service.ts
    . I don't think we have/use a config service.
  • p

    porcellus

    6 months ago
    Something like this
    @Injectable()
    export class YourService {
        constructor(@Inject(ConfigInjectionToken) private config: AuthModuleConfig) {
        }
    }
  • p

    porcx

    6 months ago
    Thanks @User for the quick response.
    configService
    in nest js helps to get the env vars when injected. Somethig like this in app.module.ts
    TypeOrmModule.forRootAsync({
          useFactory:async (config: ConfigService) => ({
            type: 'postgres',
            host: config.get('POSTGRES_HOST'),
            port: config.get('POSTGRES_PORT'),
            username: config.get('POSTGRES_USER'),
            password: config.get('POSTGRES_PASSWORD'),
            database: config.get('POSTGRES_DATABASE'),
          }),
          inject: [ConfigService]
        })
    I want to do something similar to AuthModule as well
  • p

    porcellus

    6 months ago
    oh I see, just a few mins, I'll set something up locally
  • p

    porcx

    6 months ago
    Sure. Thanks again.
  • p

    porcellus

    6 months ago
    basically instead of
    useValue
    you should have the
    useFactory
    and
    inject
    in the
    forRoot
    of auth.module
  • p

    porcx

    6 months ago
    @User I am sorry but I didn't get you here. but using
    useFactory
    How will i get appInfo, connectionURI, apiKey, these values. I am new here so please don't mind for my silly questions