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 - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Section introduction2m 33s
-
(Locked)
Setting up the sign-up route2m 24s
-
(Locked)
Designing the sign-up form2m 53s
-
(Locked)
Implementing show/hide password functionality4m 40s
-
(Locked)
Validating password2m 32s
-
(Locked)
Registering user to the database6m 50s
-
(Locked)
Configuring login page2m 12s
-
(Locked)
Validating user and sending cookie4m 41s
-
(Locked)
Reading a cookie2m 13s
-
(Locked)
Rendering DOM based on login status3m 48s
-
(Locked)
Implementing logout1m 20s
-
(Locked)
Configuring Express-Session2m 54s
-
(Locked)
Sending and reading session cookie3m 40s
-
(Locked)
Storing sessions in MySQL3m 44s
-
(Locked)
Destroying the session: Logout1m 42s
-
(Locked)
Optimizing session storage4m 15s
-
(Locked)
Implementing JWT token6m 51s
-
(Locked)
Validating request with middleware5m
-
(Locked)
Conditional rendering with token6m 14s
-
(Locked)
Hashing the password on sign-up3m 51s
-
(Locked)
Validating login credentials2m 15s
-
(Locked)
Finalizing MyStore application4m 20s
-
(Locked)
-
-