rp
03/22/2022, 7:52 AMyoyojoe
03/22/2022, 7:53 AMPik
03/22/2022, 8:37 AMPik
03/22/2022, 8:38 AMPik
03/22/2022, 8:39 AMPik
03/22/2022, 8:40 AMrp
03/22/2022, 8:42 AMPik
03/22/2022, 8:43 AMrp
03/22/2022, 8:45 AMDeleted User
03/22/2022, 9:54 AMrp
03/22/2022, 9:55 AMDeleted User
03/22/2022, 9:57 AMrp
03/22/2022, 10:01 AMDeleted User
03/22/2022, 10:10 AMporcx
03/22/2022, 10:51 AMstatic 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 ?rp
03/22/2022, 10:55 AMporcellus
03/22/2022, 11:00 AMconfigService
are you referring to?porcellus
03/22/2022, 11:01 AMsupertokens.service.ts
. I don't think we have/use a config service.porcellus
03/22/2022, 11:02 AM@Injectable()
export class YourService {
constructor(@Inject(ConfigInjectionToken) private config: AuthModuleConfig) {
}
}
porcx
03/22/2022, 11:05 AMconfigService
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 wellporcellus
03/22/2022, 11:13 AMporcx
03/22/2022, 11:13 AMporcellus
03/22/2022, 11:14 AMuseValue
you should have the useFactory
and inject
in the forRoot
of auth.moduleporcx
03/22/2022, 11:23 AMuseFactory
How will i get appInfo, connectionURI, apiKey, these values. I am new here so please don't mind for my silly questionsporcellus
03/22/2022, 11:25 AMporcellus
03/22/2022, 11:32 AMts
import {
MiddlewareConsumer,
Module,
NestModule,
DynamicModule,
FactoryProvider,
ModuleMetadata,
} from '@nestjs/common';
import { ConfigInjectionToken, AuthModuleConfig } from './config.interface';
type ModuleRootConf = Omit<FactoryProvider<AuthModuleConfig>, "provide" | "scope"> & Pick<ModuleMetadata, 'imports'>;
@Module({
providers: [],
exports: [],
controllers: [],
})
export class AuthModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
}
static forRoot({ useFactory, inject, imports }: ModuleRootConf): DynamicModule {
return {
providers: [
{
useFactory,
inject,
provide: ConfigInjectionToken,
},
],
imports,
exports: [],
module: AuthModule,
};
}
}
porcellus
03/22/2022, 11:33 AMconfigure
, you should do that I just didn't have the full setup locally πporcellus
03/22/2022, 11:34 AMforRoot
interface. maybe it'd be better renamed to forRootAsync
porcx
03/22/2022, 11:51 AMtype ModuleRootConf = Omit<FactoryProvider<AuthModuleConfig>, "provide" | "scope"> & Pick<ModuleMetadata, 'imports'>;
porcellus
03/22/2022, 11:52 AM