Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I figured it out, although I don't love the answer.</p> <p>tl;dr; - use maxAge instead of expires.</p> <hr> <p>The issue was rooted in the expiration date set on each cookie (which is automatically set by Express). I noticed that every cookie that was set had the same expiration date, which eventually ended up being in the past and hence instantly expiring.</p> <p>The cause of that was here:</p> <pre><code>cookie: { expires : new Date(Date.now() + 3600000) } </code></pre> <p>The new Date was being created only once, upon server start. That was causing the expiration date to be the same every time. Based on code in the original post, I can't figure out why it doesn't work and yet every example I've found online uses the exact same code. I verified this by defining a function that created this Date, and checking that it only got called upon server start.</p> <p>To fix this issue, I am defining maxAge instead of "expires". maxAge takes a number of milliseconds, rather than a date, and it appears to be setting the expiration date on all cookies correctly.</p> <p><strong>I would love to hear if anyone can explain why this is happening in the first place, since others seem to use it successfully. Any thoughts?</strong></p> <p>See my working code below</p> <pre><code>app.configure(function(){ app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.engine('html', consolidate.swig); app.set('view engine', 'html'); swig.init({ root: '.', allowErrors: true, // allows errors to be thrown and caught by express instead of suppressed autoescape: false}); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser("[mysecrethere]")); app.use(express.session({ store: sessionStore, cookie: { maxAge : 3600000 } //1 Hour })); app.use(passport.initialize()); app.use(passport.session()); app.use(flash()); app.use(expressValidator); app.use(express.static(path.join(__dirname, 'public'))); //Dynamic helpers app.use(require('./helpers/DynamicHelpers')); app.use(app.router); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload