The tutorial demonstrates configuring authentication in a NestJS gateway microservice. It covers connecting to an auth microservice via TCP, implementing a custom auth context, attaching user data to downstream requests, and verifying the implementation using a GraphQL playground and JWT-based authentication.
Length 18:00
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #authentication #graphql #nestjs #microservices #jwt #gateway #docker #coding #api #software-development
0:01 Okay, so next up we're gonna add authentication 0:04 to our gateway microservice so that when 0:08 requests come in to our GraphQL server on the gateway, they will 0:12 be authenticated using our normal JWT process. 0:17 So to do this, we're gonna have the gateway microservice 0:20 send a 0:21 request to the auth microservice using 0:24 our TCP transport layer and the NestJS 0:28 microservices package. So let's go ahead and set this up. 0:32 We will go into the gateway.module and add 0:36 a new section to the imports array, where we'll go ahead and 0:39 import 0:40 ClientsModule.registerAsync, 0:45 and then we'll provide an array of clients that we're gonna configure. 0:48 In our case, it will just be the auth service 0:51 that we're gonna configure. 0:52 So let's import the auth service from app/common as our injection 0:56 token, and then we will use the useFactory to set 1:00 up the configuration of this 1:04 client. So go ahead and make sure we inject the config 1:07 service, and now 1:08 we can expose the configuration object. 1:11 Also, don't forget to provide the 1:14 inject property where we actually inject the config 1:18 service so that it's available in the useFactory. 1:22 So we'll start off with specifying the transport layer. 1:26 In our case, we're gonna use transport.tcp, 1:30 and then we'll specify the options. 1:32 So we'll use our familiar options where we have the host, and 1:36 we'll use the configService.getOrThrow to 1:40 extract the auth host. And then we'll get the 1:43 port using configService.getOrThrow 1:49 authPort. 1:52 So with this, we'll have to go into our .env file 1:55 and make sure we 1:56 provide the auth host and auth port. 2:00 So let's go ahead and do that. We'll specify the auth host 2:03 is equal to auth, 2:04 which is the service name we define in our Docker Compose. 2:08 And then we have the auth port, which we know will be listening on port
The rest of the transcript is for members.
Sign in