#[Solved] useFactory. Array "jnject" of services return service name without method but

5 messages · Page 1 of 1 (latest)

crimson halo
#

i have an array of providers that will be passed in another array and that array will be specify in provide option of LoginModule.

const providersArray = [LoginService,TokenService, JwtService];
export const providers = [...providersArray, serviceConstructorProviders, serviceConstructorDB];

and i have a custom provider that use usefactory (i tried use class and use exist). Logic in useFactory inject providersArray and return object with keys - values where values are providers in inject.

const serviceConstructorProviders = {
  provide: 'Providers',
  useFactory: (...services)=>{const providers = {}; services.map((prop)=>{providers[prop] = prop}); return providers},
  inject: providersArray
}

serviceConstructorProviders was mentioned in providers array earlier.
and then i need to use @Inject('Providers') and get that object in LoginService.service.ts. But i got only JwtService in my object. I tried to look why is so and find out that in inject array that in useFactory everything is good but in arguments of useFactory function i got something like this:

LoginService {}
TokenService {}
JWTservice {
...all arguments that need to be there
}

JWTservice is a service of nest.js from jwt authorization.
honestly i dont know what i need to do. If somebody can help, please help. One of the solution that i cant do but can assume is i need to get in object token of those Services.

#

PS: use class causes error about type that need to be in provider option didnt match with use class and all of those providers.

#

And sorry for my bad english)

crimson halo
#

Wow i am really dumb tho

#

So its solved. I have spend more 6 hours to solve it when it was solved in first place