Closed mikhin closed 10 months ago
Hello @mikhin,
Can you please provide the module definition where you are injecting your Service
?
@Lokicoule , thanks for the fast response!
import { Module } from '@nestjs/common';
import { AdminsController } from './admins.controller';
import { AdminsService } from './admins.service';
@Module({
controllers: [AdminsController],
providers: [AdminsService],
})
export class AdminsModule {}
Thanks!
And where are you importing this AdminsModule
? Because based on the AppModule
you are not importing it anywhere so DI containers are not shared between these 2 modules.
Sorry, for misspelling, it imported as Module
in AppModule.
I guess it's missing an import inside AdminsModule.
From my experience, it's better to have an atomic approach for managing module composition.
If you extract cognito registering logic to a new module let's call it CognitoModule
and import this module inside your AdminsModule
does it work?
For example only: (@nestjs-cognito
version is outdated here so the DX is not the same)
https://github.com/Lokicoule/nestjs-graphql-boilerplate/blob/main/apps/users-application/src/cognito/cognito.provider.module.ts
https://github.com/Lokicoule/nestjs-graphql-boilerplate/blob/main/apps/users-application/src/users/presentation/users-presentation.module.ts
Thank you!
I thought it was supposed to work globally if I import into an AppModule
?
At least that's how it works with CognitoAuthModule
- I do registerAsync
in AppModule
and then use Authorization
, CognitoUser
decorators in different modules, without additional imports within those modules.
It's a very good point and I forgot about it, but it's as simple as that:
CognitoModule
from the core package is not globalAuthCognitoModule
from the auth package is global.This design decision was made to simplify imports when using the auth package as the API entry point while enforcing specific importation requirements when using the core package.
In your initial code, instead of using CognitoModule
, go for AuthCognitoModule
. It essentially acts as a convenient adapter for CognitoModule
, and it should work seamlessly.
Thanks for clarifications and fast answers! Really appreciated!
I have the following code:
and I have the error:
How can i fix it?