I'm using in every Controller code like @UseInterceptors(ClassSerializerInterceptor)
so I decided make it global and was trying to setup it with no luck.
I was trying without and with new
and ended up with something like this totally not working.
app.useGlobalInterceptors(new ClassSerializerInterceptor(new Reflector()));
I checked NestJS source code and I assume that it cannot be used as global but it should.
In order to set up the interceptor, we use the @UseInterceptors() decorator imported from the @nestjs/common package. Like pipes and guards, interceptors can be controller-scoped, method-scoped, or global-scoped. Hint The @UseInterceptors() decorator is imported from the @nestjs/common package.
Serialization is a process that happens before objects are returned in a network response. This is an appropriate place to provide rules for transforming and sanitizing the data to be returned to the client. For example, sensitive data like passwords should always be excluded from the response.
They are basically express middleware functions.
Have you tried using this line of code:
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With