diff --git a/index.js b/index.js index 9615346c..039c6c00 100644 --- a/index.js +++ b/index.js @@ -76,6 +76,7 @@ var defer = typeof setImmediate === 'function' * @param {Boolean} [options.proxy] * @param {Boolean} [options.resave] Resave unmodified sessions back to the store * @param {Boolean} [options.rolling] Enable/disable rolling session expiration + * @param {Function} [options.sessionid] Manually set session ID * @param {Boolean} [options.saveUninitialized] Save uninitialized sessions to the store * @param {String|Array} [options.secret] Secret for signing session ID * @param {Object} [options.store=MemoryStore] Session store @@ -99,6 +100,8 @@ function session(options) { // get the session store var store = opts.store || new MemoryStore() + var getManualSessionId = options.sessionid || function(req) {}; + // get the trust proxy setting var trustProxy = opts.proxy @@ -156,7 +159,7 @@ function session(options) { // generates the new session store.generate = function(req){ - req.sessionID = generateId(req); + req.sessionID = getManualSessionId(req) ? getManualSessionId(req) : generateId(req); req.session = new Session(req); req.session.cookie = new Cookie(cookieOptions); @@ -214,7 +217,7 @@ function session(options) { req.sessionStore = store; // get the session ID from the cookie - var cookieId = req.sessionID = getcookie(req, name, secrets); + var cookieId = req.sessionID = getManualSessionId(req) ? getManualSessionId(req) : getcookie(req, name, secrets) // set-cookie onHeaders(res, function(){ diff --git a/package.json b/package.json index adadb821..c981740e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "express-session", + "name": "@hokify/express-session-manual", "version": "1.17.1", "description": "Simple session middleware for Express", "author": "TJ Holowaychuk (http://tjholowaychuk.com)",