Troubleshooting JavaScript Cookie Expiration and Session Issues

In this meeting, the State Changers discussed a problem with cookies in JavaScript code. A participant is experiencing an issue where despite setting their cookie expiration to a week ahead, the browser reads it as, "will expire at the end of this session." The team suggested that the error might be due to a miscalculation because JavaScript operates in milliseconds.


The script showed that the participant attempted to set two cookies, with an expiration time based on a calculated day-store variable. Another participant suggested that the problem may be due to the way the expiration date is set, which might not be in milliseconds and that the date is not formatted correctly since it's currently being treated as an object. Several corrections were recommended: 1. The date should be expressed in universally understandable form using .toUTCString(). 2. There might be an inconsistency with a double space occurring after a semicolon, which might cause an issue. It was recommended to reduce it to a single space. 3. It was recommended to use console.log to print out the cookie string being written to the code to check for potential issues. 4. The same corrections made for the first cookie (converting the expiry date to a string and ensuring correct spaces) should be applied to the second cookie string as well. 5. It was noted that there seem to be two cookies and they might be overwriting each other. At the end of the session, they advised the member to build and test the code, debug it using the console and share results in forums for further discussion if problems persist. No specific applications or tools like "Xano", "WeWeb", "FlutterFlow" and others were mentioned during the meeting. JavaScript was the main programming language discussed during the session.


(Source: Office Hours 7/21 )

State Change Members Can View The Video Here
chris-montgomery-smgTvepind4-unsplash.jpg

View This Video Now

Join State Change Risk-Free