0:00 Okay, so now that we can actually generate a JWT 0:02 and set it as a cookie, 0:04 let's go ahead and create a strategy that we can use to authenticate that 0:08 JWT and actually apply it to our GraphQL 0:12 and REST endpoints so that they are secured from external 0:16 access. 0:17 So we'll follow a very similar strategy as we did with the local 0:21 strategy. We'll go ahead and create a new 0:24 jwt.strategy, 0:27 and this will be an injectable class that will be called 0:32 JWTStrategy, 0:34 which will be extending, again, the Passport strategy from 0:38 NestJS Passport. And if you recall, this is a 0:42 function constructor that takes in the strategy 0:45 that we wanna use. 0:46 So let's go ahead and import the 0:50 strategy 0:52 from passport-jwt this time, because this is the underlying 0:56 strategy we want to be utilizing. And then we pass that 0:59 in to the constructor here, 1:02 and then we pass that in to the function call here, 1:05 and we can now 1:07 fill out the rest of our JWT strategy. 1:10 So firstly, we'll create a constructor where we will 1:13 launch a 1:14 super call and provide an options object where we 1:18 need to specify some parameters. So the first, 1:22 importantly, will be the JWT from 1:25 request parameter, and what this is going to do is it's going to 1:30 tell the JWT strategy where to get the 1:33 JWT from on the incoming request. 1:37 So in our case, we know that this is a cookie, so we want to 1:41 look at the cookies property on the incoming request, which is where the 1:45 cookies will be set after we configure the cookie parser 1:49 library later on. 1:51 So to actually configure this, to extract the JWT cookie 1:55 correctly, we're gonna use the 1:57 extractJWT 2:00 import, which is gonna be a namespace from 2:04 passport-jwt. 2:06 And then we're gonna go ahead and call
The rest of the transcript is for members.
Sign in