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.

Rendering DOM based on login status

Rendering DOM based on login status

Now, let's implement the main functionalities and features of logging in. So let's once again go through the requirement, we want that when the user is not logged in, the edit and delete buttons should not be visible. The Add product menu should not be visible. The signup and login menu should get replaced by a logout option. We'll do all of this using the cookie value. So inside the app controller file, let me comment on the console statement and return the cookie value. I'll give the property is logged in and assign the cookie dot is logged in. The reason to return a cookie here with a property is because we will render the DOM elements based on the user login. So we will need a variable which we can use inside the template. I'll open the home EJS template and just above the edit and delete buttons, I'll give an if condition that if the is logged in is equal to true. I'll shift the below button division inside the if condition. The reason I've given true as a string and not as…

Contents