#Nest CLS package
1 messages · Page 1 of 1 (latest)
how the injection and usage looks like?
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.
Alright, so I did something like this and then importing that module in other modules where I'm using that AuthStore
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""
Did you also register ClsModule for root and enabled the middleware/interceptor?
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
There's multiple ways of wrapping the context, some of which only work with some transports, sadly.
So now I have a provider. But I have a question - Is it possible to retrieve the user from the store by a static method? And if yes will it be a safe way?
In a static method, you mean outside the context of any request? Or outside the context of dependency injection?
Outside of DI