The tutorial demonstrates setting up authentication in a NestJS application using Passport strategies. The process includes implementing local login with email and password, hashing passwords with bcrypt, creating guards and decorators for user context, and configuring JWT-based authentication with secure HTTP-only cookies, verified through Postman.
Length 18:53
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #nestjs #authentication #passport #jwt #bcrypt #coding #webdevelopment #programming #tutorial #backend
0:00 So we've cleaned things up a little bit, and now we are actually correctly setting 0:03 up the JWT module. This is all great, and we're ready to finally 0:07 start implementing our authentication. 0:10 So in order to do this, like I said before, 0:12 we're taking advantage of 0:13 Passport, which is a common and popular 0:17 authentication library that makes authentication super easy to 0:20 set up. 0:21 So a Passport has the idea of strategies in NestJS, 0:26 where you can implement a new strategy for each kind of authentication 0:30 we want to use. So we'll have a, a strategy for logging in with an email 0:34 and 0:34 password, and then we'll also have a strategy for 0:36 authentication with 0:38 a JWT. So let's keep things organized here in our 0:41 auth 0:42 folder. Let's create a new strategies folder, and 0:46 we can start off by creating our first strategy. 0:48 This will be the local.strategy. And this is going 0:52 to be the strategy that allows us to log in with a user's 0:56 email and password, which essentially will start off the 0:59 authentication flow. 1:00 So this will be a normal injectable class here, and 1:04 so we'll export the local strategy here. 1:08 And this importantly is gonna extend the Passport strategy 1:12 that we want to actually use here. 1:15 And so make sure we import up top 1:19 the Passport strategy 1:24 from 1:25 nestjs/passport. 1:28 And now we pass in the actual strategy we want to use in this 1:32 case. So you can see here we have two different 1:35 strategies out of the box from what 1:36 we've already installed. This will be the Passport local strategy. 1:41 So this is what essentially takes care of most of the work here. 1:45 We just provide the strategy we wanna use, and then we need to take 1:49 care of some basic configuration in this class. 1:51 Firstly, we're gonna have a constructor here,
The rest of the transcript is for members.
Sign in