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.
Sending and reading session cookie - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Sending and reading session cookie
Now, we are going to set the cookie value with the session and send it to the client. Here we are already sending the cookie is logged in. And as we discussed earlier, storing cookies this way is not an ideal way for secure authentication. So we will use the request.session object instead and set the cookie. First, let me give the request decorator and the request property of type request. And then instead of the response.cookie, I'll give the request.session.isLoggedIn and set it to true. Now here the issue is, we cannot set custom property to the session, and that is why it is showing the error. So to solve this, let's make the isLoggedIn the known property of the session class. I'll open the main TS and open the express session module declaration file. Now here we will find the session class, I'll scroll down. And here we have the session class. I'll add the isLoggedIn of type string to the class properties. And now if we check the user controller, the error is gone. Same way, I'll…
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)
-
-