Unable to Access Cookies Created by Server

Question:
I am attempting to create a cookie with node.js, and access it on the client side with javascript/html. However, no matter what I try, I cannot get the value of the cookie (it always returns “null”). I’m not sure what I’m doing wrong here, so any help is appreciated!

Repl link:
https://replit.com/@SevenT33N/Chat-App-With-User-Logins?v=1

If your cookie is HttpOnly you cannot access it.
You can check the details of the cookie using the inspector tools.

Just a little thing, in your code, when setting the cookie, you’re using the res.cookie method with the expire option but the correct option is expires (not expire).

Also, if you set httpOnly to true , the cookie will not be accessible via JavaScript for security reasons, if you need to access the cookie on the client side via JavaScript set it to false.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.