#Nest CLS package

1 messages · Page 1 of 1 (latest)

glass cove
#

Hey,
I'm trying to set my custom wrapper for ClsService to make my own methods,

but when I inject the AuthStore and call it somewhere it says that:
TypeError: this.authStore.setLoggedUser is not a function

tawdry moat
#

how the injection and usage looks like?

austere gate
#

Right, so you provide the existing ClsService under the injection token of AuthStore. That means when an AuthStore is requested for injection, what actually gets injected is plain ClsService, which obviously does not have the setLoggedUser method.

#

The way to do this correctly would be to use conposition instead of inheritance - inject ClsService into your AuthStore and make your AuthStore a proper provider.

glass cove
#

Alright, so I did something like this and then importing that module in other modules where I'm using that AuthStore

glass cove
#

But I get "No CLS context available, please make sure that a ClsMiddleware/Guard/Interceptor has set up the context, or wrap any calls that depend on CLS with "ClsService#run""

austere gate
glass cove
#

Yeah I haven't and that was the case

#

Also for the first time when I discovered ALS I tried to save logged user in guard by using enterWith but it wasn't working properly

#

Then I used your package and it was good. I think that's because your package seems to wrap whole context in middleware using run

austere gate
glass cove
austere gate
glass cove
#

Outside of DI