Skip to main content


Showing posts with the label Cookie

NestJS JWT Auth Cookie Series - Part-2 - Generating Access Token

In this article, we target to generate the jwt authentication and store it in the HttpOnly cookie for user authentication.  Part-1  completely explains implementing user registration in the nestjs application. Implement Logic To Validate User Credentials: First, let's create a model to store the valid user. src/models/current.user.ts: export class CurrentUser { userId: number; firstName: string; lastName: string; email: string; } Now we have to implement the logic for the login endpoint that is to validate user email and password. src/users/users.service.ts: public async validateUserCredentials(email: string, password: string):Promise<CurrentUser> { let user = await this.user.findOne({ email: email }); if (user == null) { return null; } const isValidPassword = await, user.password); if (!isValidPassword) { return null; } let currentUser = new CurrentUser(); currentUser.userId = user.userId;

NestJS JWT Auth Cookie Series - Part-1 - User Registration

This is the first installment of the NetsJS JWT Auth Cookie Series. In this part our main focus on user registration by the NestJS endpoint. PostgreSQL Database: For this demo, I'm using the free open-source PostgreSQL database. Here I'm going to use the PostgreSQL docker image because it is easy and fast to set up and configure.  Click here to getting started with PostgreSQL docker . Run the following database query to create the 'User' table. CREATE TABLE User( UserId SERIAL PRIMARY KEY NOT NULL, FirstName VARCHAR(200) NULL, LastName VARCHAR(200) NULL, Email VARCHAR(200) NOT NULL, Password VARCHAR(200) NOT NULL, RefreshToken VARCHAR(1000) NULL, RefreshTokenExp DATE NULL ) Create A NestJS App: Let's begin our demo by creating a sample NestJS application. Command To Install NestJS CLI npm i -g @nestjs/cli Command To Create App nest new your_project_name Install ORM And PostgreSQL NPM Packages: ORM packages are essential to install because they prov