#Dependency injection error

60 messages · Page 1 of 1 (latest)

wraith patrol
#

hi, I getting this error while registering in authservice in cqrs.photos have userModel, error and authService

rough trail
#

Why do you have a circular dependency on the command bus?

wraith patrol
#

yes, I did exports:[CommandBus] in the userModel because of it.

rough trail
#

But shouldn't the CommandBus be free of logic that comes from services? It should just handle calling the correct handlers, right?

wraith patrol
#

you're right, I tried a lot and I couldn't solve the problem. How can I solve this problem exactly?

rough trail
#

Well, first problem is that the command bus isn't a registered provider for the AuthModuke

wraith patrol
rough trail
wraith patrol
#

postmande does not give any error in terminal while getting this error

rough trail
#

You just get a 500 with no error in the terminal where your server is running?

wraith patrol
#

yes I get this not when adding color and cars but only during register

rough trail
#

Do you have a custom exception filter being used?

wraith patrol
#

yes there is

rough trail
#

Well that explains why there's no log. You should probably log that error

wraith patrol
#

I commented out the customerror in maint.ts and got the same error.How can I log error

rough trail
#

It should be loved to the console if it's an unknown error

wraith patrol
#

When I log the user in controller and authservis, the values ​​come as in the photo and I get this error

rough trail
#

What command are you trying to execute? That's a UUID, not some command class

wraith patrol
#

my authservis is like this, I think the error comes from here

rough trail
#

Can you show the create user command?

wraith patrol
#

my create user metods

rough trail
#

Do you have the command handler added to a providers array?

wraith patrol
#

yes, there is the provider part {...UserCommandHandlers,
...UserQueryHandlers } I added it as

rough trail
#

That's super weird. Can you provide access to the code and I'll take a look locally?

rough trail
#

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?

rough trail
#

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

wraith patrol
#

I deleted CoomandBus from authmodulde providers and started getting dependency injection error. Should I use CqrsModule instead of CommandBus in AuthService?

rough trail
#

Did you add the CqrsModule to the AuthModule's imports?

wraith patrol
#

Thaks very much solved problem

wraith patrol
#

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?

rough trail
#

What's the error with injection?

wraith patrol
#

this my error

rough trail
#

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

wraith patrol
rough trail
#

So where does AbstractUserRepository come from?

wraith patrol
#

AbstractUserRepository is my repository I inject it in constructor in authService

rough trail
#

But where do you define the provider

wraith patrol
#

I added AbstractUserRepository in UserModel in providers

rough trail
#

What does that have to do with AuthModule

wraith patrol
#

you are right I tried to fetch the user with GetUserByEmailQuery instead of AbstractUserRepository got passoword error

wraith patrol
#

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

rough trail
#

So your GetUserByEmailQuery type doesn't have a password property

wraith patrol
#

yes GetUserByEmailQuery only fetch users by mail

rough trail
#

So typescript is telling you you can't set that property, it doesn't exist

wraith patrol
#

yes you're right, I'm trying too, I'couldn't solve the problem

rough trail
#

So why not use a type where you can add that property?

#

This isn't anything nest specific, this is Typescript basics

wraith patrol
#

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 }

rough trail
#

I don't think you understand what that error is telling you

wraith patrol
#

I solved the problem

#

I am getting such an error. User comes, but user.password is undefined. What could be the reason?

rough trail
#

Looks like you should be accessing user.user.password

#

What does the GetUserByEmailQuery command return type-wise?

wraith patrol
#

thanks I solved proble