Skip to content

Commit fd82d13

Browse files
committed
feat: add support to dynamic cookie generation
1 parent 4930de7 commit fd82d13

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ var defer = typeof setImmediate === 'function'
7070
* Setup session store with the given `options`.
7171
*
7272
* @param {Object} [options]
73-
* @param {Object} [options.cookie] Options for cookie
73+
* @param {Object|Function} [options.cookie] Options for cookie
7474
* @param {Function} [options.genid]
7575
* @param {String} [options.name=connect.sid] Session ID cookie name
7676
* @param {Boolean} [options.proxy]
@@ -158,7 +158,7 @@ function session(options) {
158158
store.generate = function(req){
159159
req.sessionID = generateId(req);
160160
req.session = new Session(req);
161-
req.session.cookie = new Cookie(cookieOptions);
161+
req.session.cookie = new Cookie(typeof cookieOptions === 'function' ? cookieOptions(req) : cookieOptions);
162162

163163
if (cookieOptions.secure === 'auto') {
164164
req.session.cookie.secure = issecure(req, trustProxy);
@@ -193,7 +193,8 @@ function session(options) {
193193

194194
// pathname mismatch
195195
var originalPath = parseUrl.original(req).pathname || '/'
196-
if (originalPath.indexOf(cookieOptions.path || '/') !== 0) {
196+
var resolvedCookieOptions = typeof cookieOptions === 'function' ? cookieOptions(req) : cookieOptions
197+
if (originalPath.indexOf(resolvedCookieOptions.path || '/') !== 0) {
197198
debug('pathname mismatch')
198199
next()
199200
return

0 commit comments

Comments
 (0)