diff --git a/index.js b/index.js index 816a15a..9e98b13 100644 --- a/index.js +++ b/index.js @@ -66,12 +66,12 @@ function formatOpts(opts) { if (!('maxAge' in opts)) opts.maxAge = opts.maxage; // defaults - if (opts.overwrite == null) opts.overwrite = true; - if (opts.httpOnly == null) opts.httpOnly = true; + if (util.isNil(opts.overwrite)) opts.overwrite = true; + if (util.isNil(opts.httpOnly)) opts.httpOnly = true; // delete null sameSite config - if (opts.sameSite == null) delete opts.sameSite; - if (opts.signed == null) opts.signed = true; - if (opts.autoCommit == null) opts.autoCommit = true; + if (util.isNil(opts.sameSite)) delete opts.sameSite; + if (util.isNil(opts.signed)) opts.signed = true; + if (util.isNil(opts.autoCommit)) opts.autoCommit = true; debug('session options %j', opts); diff --git a/lib/util.js b/lib/util.js index b3a1a28..67c61ca 100644 --- a/lib/util.js +++ b/lib/util.js @@ -35,5 +35,9 @@ module.exports = { return crc(JSON.stringify(sess)); }, + isNil(val) { + return val === null || typeof val === 'undefined'; + }, + CookieDateEpoch: 'Thu, 01 Jan 1970 00:00:00 GMT', };