Sunday 24 May 2020

Express-session help? Cookie maxAge resets on each refresh/request

Hey guys. First post here, really hoping I can get some help. I've spent about 4 hours googling this to try and find some sort of solution that works. Nothing is helping. I'm using express and express-sessions.I'm just trying to make a cookie that expires in 5 seconds and have the time left of the cookie display on a page. The problem is, every single time I refresh the page, the cookie life resets. This shouldn't be happening.Here's my code (leaving some unrelated stuff out)index.jsconst express = require("express"); const app = express(); const path = require("path"); const expbs = require("express-handlebars"); const session = require("express-session"); ... app.use(session({ secret: "test session signature", resave: false, saveUninitialized: false, rolling: false, cookie: { maxAge: 5000 } })); ... app.get("/", (req,res)=>{ if(req.session.views){ req.session.views++; // set handlebars variables to display the cookie life and view count res.locals.testViews = req.session.views; res.locals.testExpire = req.session.cookie.maxAge; } else { req.session.views = 1; } res.render("index", homeData); }); I've already tried several combinations of the resave, savuninitialized, and rolling parameters. No matter what combination I choose, the maxAge gets reset on each page request.What the hell is going on?

Submitted May 25, 2020 at 06:01AM by cuboidofficial

No comments:

Post a Comment