The developer integrates JWT authentication using Passport and NestJS, installs necessary dependencies, configures environment variables, and refactors microservice configurations. They isolate service-specific .env files, update Docker Compose settings, and adjust port configurations in the application modules.
Length 9:56
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #nestjs #passport #jwt #microservices #docker #configuration #authentication #typescript #programming #backend
0:00 Okay, so in order to start implementing our JWT 0:04 authentication with Passport, we'll go ahead and stop 0:07 our app from running, and we'll need to install some new 0:11 dependencies here. I'll go ahead and install 0:14 nestjs/passport as well as passport itself, 0:19 and then finally passport-local here, which will be our first authentication 0:23 strategy. We'll also go ahead and install the types for 0:27 passport-local here as a development dependency. 0:30 So we're also gonna want to install the dependencies to be able to implement our 0:34 JWT authentication. So let's go ahead and pnpm 0:38 install nestjs/jwt as well as 0:41 passport-jwt. And 0:44 nestjs/jwt is a package that helps with the JWT 0:48 manipulation. And then we'll go ahead and install the development dependencies 0:51 for 0:51 types/passport-jwt. And once we have this 0:55 installed, we'll go ahead and start our app back up by running 0:59 docker compose up. So now we're actually ready to start 1:02 writing the code 1:03 for the AuthService here. So let's go ahead and open up the 1:07 auth.module. We're gonna have to import the 1:10 JWT module now, and we import the 1:15 JWT module up top from 1:18 nestjs/jwt. So we need to 1:22 configure the JWT module with some environment variables, 1:26 and we can accomplish this by calling registerAsync 1:30 on this. And inside of here, we can use a useFactory and get 1:34 access to the config service. And so we're gonna return an 1:38 object here that has some environment variables, 1:41 the important thing being the JWT_SECRET value, which is the 1:45 special token that the JWT module uses to 1:49 actually verify incoming JWTs against to 1:53 make sure that they're valid. So when we sign a new JWT, we use the 1:57 secret, and when we verify, we use the same secret. 2:00 So it's important that we keep this hidden away in an 2:03 environment 2:03 variable. So we'll call configService, service
The rest of the transcript is for members.
Sign in