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 bcrypt.compare(password, user.password); if (!isValidPassword) { return null; } let currentUser = new CurrentUser(); currentUser.userId = user.userId;