0:01 So to do this, we'll go back to the AuthController, 0:04 and this is gonna be very 0:05 simple to do because NestJS microservices are no different 0:09 from HTTP controllers. We can still apply guards, 0:14 interceptors, pipes as we normally would. 0:17 So all we're gonna do is annotate this 0:21 route here with @UseGuards and pass in 0:25 our GqlAuthGuard. Now, make sure, of course, this is the 0:28 GqlAuthGuard inside of our local guards folder and 0:32 not the common one. So pass in our GqlAuthGuard, 0:37 which we know is actually executing the JWT strategy 0:41 here underneath the hood. Now, there's gonna be a small 0:44 modification we need to make to this strategy, and that's, of course, going 0:48 to be this extractor function that actually pulls off 0:52 the cookie from the request. So in this case, we're pulling off 0:56 request.cookies.authentication for any GraphQL 0:59 requests. However, if this request is coming in on our 1:03 gRPC server, we're not gonna have request.cookies. 1:07 Instead, as we just saw, the JWT is simply going to be 1:10 available on the token property here. 1:15 Now, this request object will be the underlying 1:19 gRPC payload in the microservices example. 1:23 So we can simply check to see here if 1:26 request.cookies.authentication 1:29 is undefined, then we'll use the or here and tell 1:33 it to check for the request.token instead, which is where we 1:37 know we are going to be extracting that JWT from 1:41 on the incoming authenticate request payload. 1:46 And so finally, we also need to update the type here. 1:48 We'll change this to type any since it can be a request or 1:53 an authenticate request. So now we've updated this strategy to pull 1:57 off 1:57 the JWT from our incoming microservices call. 2:01 Now, finally, we need to make an additional change to 2:03 our authentication mechanism 2:04 because right now we're applying this 2:07 GqlAuthGuard against this gRPC message
The rest of the transcript is for members.
Sign in