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.

Reading a cookie

Reading a cookie

Previously, we validated the user credentials and based on that, we sent the cookie. Now we want that depending on the login state, that is, if the user is not logged in, then the edit and delete buttons should not be visible. This add product menu should not be visible. The signup and login options should get replaced by the logout menu. So for this, we will have to read the cookie. So inside the app controller, where we are rendering all the products, I'll just get the cookie by giving the request decorator and a property of type request from Express. I'll set a constant and get the cookie and display the cookie inside the console. Let's go to the browser and refresh the page and in the terminal we get cookie. But this cookie is in a simple text format. Instead we want the cookie in a proper key and value pair. So to get the cookie in a key and value pair, we have to parse it. Now instead of parsing the cookie using the split method like this, we will use the cookie parser…

Contents