How the generic Interceptors works
ApiKeyInterceptor
is created, decorated with @Injectable()
indicating it’s a provider that can be injected.NestInterceptor
, requiring the intercept()
method to be defined.intercept
Methodintercept()
method is where the main logic of the interceptor resides.x-api-key
header exists in the request. If not, an UnauthorizedException
is thrown.studioService
) to fetch some data related to the API key.UnauthorizedException
is thrown.studio
property for later use in the route handler.next.handle()
to pass control to the next handler (which would be the route handler).@UseInterceptors()
decorator and passing the ApiKeyInterceptor
class.publicEndpoint
route, the ApiKeyInterceptor
will run first, perform its logic, and then (assuming no exceptions are thrown) pass control to the publicEndpoint
route handler.