Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js/Express.js session management cookie to be session cookie

How can I make the connect.sid cookie itself only a session cookie instead of a persistent one?

I unsuccessfully tried

app.use(express.session({cookie: { path: '/', httpOnly: true}, secret:'eeuqram'}));

But the cookie still had the expiration timestamp.

like image 860
Ustaman Sangat Avatar asked Jan 12 '12 21:01

Ustaman Sangat


People also ask

How do you set an express session cookie?

var cookieSession = require('cookie-session') var express = require('express') var app = express() app. use(cookieSession({ name: 'session', keys: ['key1', 'key2'] })) // Update a value in the cookie so that the set-cookie will be sent. // Only changes every minute so that it's not sent with every request.

Does Express session use cookies?

express-session stores only a session identifier on the client within a cookie and stores the session data on the server, typically in a database.

How cookies can be used for session management?

The cookie allows the server to identify the user and retrieve the user session from the session database, so that the user session is maintained. A cookie-based session ends when the user logs off or closes the browser. Cookie-based session management is secure and has performance benefits over alternatives.

How do I use cookies and sessions in node js?

Cookies and sessions make the HTTP protocol stateful protocol. Session cookies: Session cookies are the temporary cookies that mainly generated on the server-side. The main use of these cookies to track all the request information that has been made by the client overall particular session.


1 Answers

 app.use(express.session({cookie: { path: '/', httpOnly: true, maxAge: null}, secret:'eeuqram'}));

The above worked. So by setting maxAge to be null, I did manage expressjs to use session cookies. Phew.

like image 72
Ustaman Sangat Avatar answered Sep 29 '22 11:09

Ustaman Sangat