question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Can cookie-session persist?

See original GitHub issue

I know this is not the good place to ask questions but this really bugs me . I cant figure out how to make cookie-session persists i set cookie-session like this:

var expiryDate = new Date(Date.now() + 24 * 60 * 60 * 1000) // 1 day
app.use(cookieSession({
  name: 'sessId',
  keys: ['test1', 'test2'],
  cookie: {
    secure: true,
    httpOnly: true,
    domain: constData.DOMAIN,
    path: '/api',
    expires: expiryDate,
    maxAge: 24 * 60 * 60 * 1000
  }
}))

then i set the session using:

req.session.user = 'blah';

after i close chrome browser and open up again i tried to access the session but itā€™s appeared null. According to my understanding i can persist session if i put expires options when creating the cookie-session middleware am i right?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
richardscarrottcommented, Feb 13, 2021

Also, Iā€™m guessing you got that incorrect snippet above from https://expressjs.com/en/advanced/best-practice-security.html#set-cookie-security-options?

0reactions
richardscarrottcommented, Feb 15, 2021

@bettafish15 yeh I ended up using maxAge too as it turns out it sets Expires under the hood rather than Max-Age anyway šŸ‘

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express cookie-session does not persist in POST request
I'm just using the cookie-session module. Problem: The cookie is not persisting in the client. Subsequent requests from the same client show anĀ ......
Read more >
Express cookie-session middleware
Simple cookie-based session middleware. A user session can be stored in two main ways with cookies: on the server or on the client....
Read more >
What are cookies? What are the differences between ... - Cisco
There are two different types of cookies - session cookies and persistent cookies. If a cookie does not contain an expiration date, it...
Read more >
Using HTTP cookies - MDN Web Docs
For example, cookies that persist in server-side sessions don't need to be available to JavaScript and should have the HttpOnly attribute. ThisĀ ...
Read more >
Load Balancer Session Persistence - Oracle Help Center
To configure load balancer cookie session persistence, you specify: The cookie name. If you do not specify a cookie name, the default nameĀ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found