How to Fix Express Sessions Cookie Error

October 19, 2022


Express Sessions Cookie Error


I ran into an error with express sessions. Every request, sessions was creating a new cookie instead of authenticating the cookie that was already made. It was also saving a new session to the store on every request. I was using the options resave: false, saveunintialized: false, httpOnly: true, secure: true. I was working on a secure connection.


The Fix


Well, I thought I was working on a secure connection. It turned out that the server couldn't validate the certificate, so as a fail safe instead of authenticating a cookie that was sent over an unsecure connection, it made a new one. When I put express sessions on a secure connection it didn't do this. It also didn't do this when I changed the secure option to false.

About the Author

Christopher Howard

Chris is a Javascript developer with a minor in UI design. He values programming in vanilla code. Fill out the form below to contact him.