From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Validating user and sending cookie

Validating user and sending cookie

Now we are going to validate the login details based on the user credentials stored inside the database. And accordingly, we will send a cookie containing the login status. So let's begin. First of all, we need to fetch the data from the login form. And for that we need a post route handler. Before we define a post route, we have to make sure that the login form is assigned with the correct action attribute path and method to post. Now inside the user controller file, I'll create a post route and set the path as login and a method user login. In this method, we will validate the user credentials and pass the cookie. But first, we need to fetch the user credentials from the database. So inside the user service file, I'll create a method, find user by username, and pass the username parameter of type string. Let me also return await this dot user repository dot find one where username. With this method, we can fetch the user data from the database. Now in the user controller, I'll pass…

Contents