If you’re building apps in Node.js then you might be familiar with  NestJS, a self-described feature-packed framework for building server-side applications. Think of it as the Laravel, Ruby on Rails or Flask for Node. NestJS allows us to rapidly build out services with the basics such as routing, validation and database access already packaged in.

Thankfully, authentication is also given first-party support, with support for various providers via passport and multiple guards, including JWT — today’s topic. Nest provides a basic  guide to JWT implementation, but it doesn’t necessarily include all the features that your typical app might require.

Let’s take a look at a custom and feature-complete implementation that you can roll in your own application. For simplicity’s sake, we’ll assume that you have an existing project based on Nest’s setup guide and a basic understanding of the various components that Nest provides.

Getting Started

Let’s start by installing Nest’s first-party authentication packages, which will provide 90% of the logic for our implementation, as well as a few external modules for additional support.

$ npm install --save @nestjs/passport @nestjs/jwt passport passport-local passport-jwt bcrypt class-validator

$ npm install --save-dev @types/passport-local @types/passport-jwt @types/bcrypt @types/jsonwebtoken

#authentication #nestjs #javascript #jwt #typescript

NestJS - Implementing Access & Refresh Token JWT Authentication
83.45 GEEK