#Dependency injection error
60 messages · Page 1 of 1 (latest)
Why do you have a circular dependency on the command bus?
yes, I did exports:[CommandBus] in the userModel because of it.
But shouldn't the CommandBus be free of logic that comes from services? It should just handle calling the correct handlers, right?
you're right, I tried a lot and I couldn't solve the problem. How can I solve this problem exactly?
Well, first problem is that the command bus isn't a registered provider for the AuthModuke
thank you I fixed the problem. There is no problem while adding color,cars, but during auth process I get this error "statusCode":500, "message": "Internal server error". What could be the reason exactly?
What's in the terminal? There should be some sort of stack trace with extra error information
postmande does not give any error in terminal while getting this error
You just get a 500 with no error in the terminal where your server is running?
yes I get this not when adding color and cars but only during register
Do you have a custom exception filter being used?
yes there is
Well that explains why there's no log. You should probably log that error
I commented out the customerror in maint.ts and got the same error.How can I log error
It should be loved to the console if it's an unknown error
When I log the user in controller and authservis, the values come as in the photo and I get this error
What command are you trying to execute? That's a UUID, not some command class
my authservis is like this, I think the error comes from here
Can you show the create user command?
my create user metods
Do you have the command handler added to a providers array?
yes, there is the provider part {...UserCommandHandlers,
...UserQueryHandlers } I added it as
That's super weird. Can you provide access to the code and I'll take a look locally?
How am I supposed to run this without mongo?
Or a docker-compose so that I can run mongo in the way you expect it to be ran?
Found the issue. You're adding the CommandBus directly instead of making use of the Nest CqrsModule which adds extra setup of handling the providers. Remove any CommandBus you've added to providers arrays and instead add CqrsModule to the imports
I deleted CoomandBus from authmodulde providers and started getting dependency injection error. Should I use CqrsModule instead of CommandBus in AuthService?
Did you add the CqrsModule to the AuthModule's imports?
Thaks very much solved problem
hello, I can't make user.password while fetching user according to email in AuthService.private readonly userRepository: GetUserByEmailQuery and fetch with user= await this.userRepository.findOne({email}) gives a dependency injection error.My aim is to bring the user according to the mail, compare the password and perform the login process. How can I do this?
What's the error with injection?
this my error
Can you show the constructor of the AuthService? Looks like you're trying to inject AbstractUserRepository, which I doubt is what you're meaning to do.
If it is what you're meaning to do, can you also show the AuthModule so I can see the available injection tokens
So where does AbstractUserRepository come from?
AbstractUserRepository is my repository I inject it in constructor in authService
But where do you define the provider
I added AbstractUserRepository in UserModel in providers
What does that have to do with AuthModule
you are right I tried to fetch the user with GetUserByEmailQuery instead of AbstractUserRepository got passoword error
I updated my codes https://github.com/mi-cloud34/nest-cleanarchitecture-carapp
I get this error when using GetUserByEmailQuery instead of AbstractUserRepository.my purpose here is whether there is a user or not, to make a password check and use this method in login
So your GetUserByEmailQuery type doesn't have a password property
yes GetUserByEmailQuery only fetch users by mail
So typescript is telling you you can't set that property, it doesn't exist
yes you're right, I'm trying too, I'couldn't solve the problem
So why not use a type where you can add that property?
This isn't anything nest specific, this is Typescript basics
async validateUser(
email:string,
password:string
): Promise<LoginUserDto | null> {
const user=await this.queryBus.execute(
new GetUserByEmailQuery(email,password)
);
console.log("userrrr",user);
here user returns null what could be the reason
userrrr { user: null }
I don't think you understand what that error is telling you
I solved the problem
I am getting such an error. User comes, but user.password is undefined. What could be the reason?
Looks like you should be accessing user.user.password
What does the GetUserByEmailQuery command return type-wise?
thanks I solved proble