In the previous article , we understand the steps to generate the JWT token and store it in the cookie. Now here we will understand steps to protect API and also about refresh token. Install passport-jwt NPM Package: We have to create a new jwt passport strategy to validate the jwt token, so we need to install the below packages. Command To Install passport-jwt Packages: npm install --save passport-jwt npm install --save-dev @types/passport-jwt Install And Setup Cookie Parser: To read the cookie in the nestjs application we have to install the below plugin. Command To Install Cookie Parser: $ npm i cookie-parser $ npm i -D @types/cookie-parser Now configure the cookie parser 'main.ts' src/main.ts: Create JWT Passport Strategy: So to apply authentication to API's we have to validate our jwt token, so to do that we need to create a new jwt passport strategy. src/users/jwt.strategy.ts: import { Injectable, UnauthorizedException } from "@nestjs/common"; im