-
Book Overview & Buying
-
Table Of Contents
Nest.js: A Progressive Node.js Framework
By :
Guards in microservices serve the same purpose as they do in normal APIs. They determine if a specific microservice handler should handle a request. Up to now, we have used guards to protect API handlers from unauthorized access. We should do the same thing to our microservice handlers. Although in our application, our microservice handler is only called from our already protected API handler, we should never assume that will always be the case.
@Injectable()exportclassRpcCheckLoggedInUserGuardimplementsCanActivate{canActivate(context:ExecutionContext):boolean|Promise<boolean>|Observable<boolean>{constdata=context.switchToRpc().getData();returnNumber(data.userId)===data.user.id;}}
The new guard looks exactly like the API CheckLoggedInUserGuard guard. The difference is in the parameters that are passed to the canActivate method. Since this guard is being executed in the context of a microservice, it will be given a microservice...
Change the font size
Change margin width
Change background colour