From c3a75aad25fb06a6fe61fedf39c3405f0e3ff45a Mon Sep 17 00:00:00 2001 From: andrewjones Date: Fri, 12 Jun 2020 16:36:50 -0400 Subject: [PATCH 1/6] Use a computed property for ttl. --- lib/config.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/config.js b/lib/config.js index ecceb64..7b6a8cc 100644 --- a/lib/config.js +++ b/lib/config.js @@ -5,10 +5,23 @@ */ 'use strict'; -const {config} = require('bedrock'); - +const {config, util} = require('bedrock'); +const cc = util.config.main.computer(); config['session-mongodb'] = { collection: 'session', - // timeout is in seconds (time for session to live on the server) - ttl: 60 * 30 }; + +// MongoStore ttl defaults to thirtyMinutes expressed in seconds. +const thirtyMinutes = 60 * 30; + +// timeout is in seconds (time for session to live on the server) +cc('session.mongodb.ttl', () => { + if(config.express && config.express.session) { +console.log('got mongo session time'); + // express session ttl is in milliseconds + const {ttl = thirtyMinutes * 1000} = config.express.session; + return Math.ciel(ttl / 1000); + } + return thirtyMinutes; +}); + From 4a7911adafba038df61f09b4f0a1c1e90996759e Mon Sep 17 00:00:00 2001 From: andrewjones Date: Fri, 7 Aug 2020 10:44:44 -0400 Subject: [PATCH 2/6] Fix computed property for ttl. --- lib/config.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/config.js b/lib/config.js index 7b6a8cc..8f93ac1 100644 --- a/lib/config.js +++ b/lib/config.js @@ -15,12 +15,11 @@ config['session-mongodb'] = { const thirtyMinutes = 60 * 30; // timeout is in seconds (time for session to live on the server) -cc('session.mongodb.ttl', () => { +cc('session-mongodb.ttl', () => { if(config.express && config.express.session) { -console.log('got mongo session time'); // express session ttl is in milliseconds const {ttl = thirtyMinutes * 1000} = config.express.session; - return Math.ciel(ttl / 1000); + return Math.ceil(ttl / 1000); } return thirtyMinutes; }); From 76c3e867a590f09e80188fc6051be1ebb037d93f Mon Sep 17 00:00:00 2001 From: Andrew L Jones Date: Fri, 7 Aug 2020 13:31:58 -0400 Subject: [PATCH 3/6] Add comment on use of Math.ceil. --- lib/config.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/config.js b/lib/config.js index 8f93ac1..82fc704 100644 --- a/lib/config.js +++ b/lib/config.js @@ -19,6 +19,8 @@ cc('session-mongodb.ttl', () => { if(config.express && config.express.session) { // express session ttl is in milliseconds const {ttl = thirtyMinutes * 1000} = config.express.session; + // round up to give the user the benefit of the doubt + // with time outs return Math.ceil(ttl / 1000); } return thirtyMinutes; From d0cf5380b4a3a0e1a94de197eec34aa5fd61ff4e Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 7 Aug 2020 15:38:03 -0400 Subject: [PATCH 4/6] Round down to ensure session does not live beyond expected ttl. Co-authored-by: Dave Longley --- lib/config.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/config.js b/lib/config.js index 82fc704..52545cf 100644 --- a/lib/config.js +++ b/lib/config.js @@ -19,10 +19,8 @@ cc('session-mongodb.ttl', () => { if(config.express && config.express.session) { // express session ttl is in milliseconds const {ttl = thirtyMinutes * 1000} = config.express.session; - // round up to give the user the benefit of the doubt - // with time outs - return Math.ceil(ttl / 1000); + // round down to ensure session doesn't live beyond configured value + return Math.floor(ttl / 1000); } return thirtyMinutes; }); - From 31d3807855a5d4d2640ef667c41b0f2a037bc282 Mon Sep 17 00:00:00 2001 From: Andrew L Jones Date: Fri, 7 Aug 2020 15:45:48 -0400 Subject: [PATCH 5/6] Add a changelog for ttl changes. --- CHANGELOG.md | 6 ++++++ README.md | 3 +++ package.json | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa21942..1bbd68a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # bedrock-session-mongodb ChangeLog +## 4.2.0 - + +### Changed +- `config.session-mongodb.ttl` is now a computed property. +- `config.session-mongodb.ttl` is now computed from config.express.session.ttl. + ## 4.1.0 - 2020-07-07 ### Changed diff --git a/README.md b/README.md index abefc43..2c8760a 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,9 @@ bedrock.start(); For documentation on configuration, see [config.js](./lib/config.js). +`config.session-mongodb.ttl` is a computed property that based off of +`config.express.session.ttl`. In order to change the ttl for sessions you will +now need to change the `config.express.session.ttl` using milliseconds. [bedrock]: https://github.com/digitalbazaar/bedrock [bedrock-express]: https://github.com/digitalbazaar/bedrock-express diff --git a/package.json b/package.json index 2c70abd..2b56d97 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ }, "peerDependencies": { "bedrock": "1.0.0 - 3.x", - "bedrock-express": "2.0.3 - 3.x", + "bedrock-express": "2.0.3 - 4.x", "bedrock-mongodb": "^7.1.0" }, "directories": { From 046a35f12350e17af1843ebd33c883783889e53f Mon Sep 17 00:00:00 2001 From: Andrew L Jones Date: Fri, 7 Aug 2020 15:47:45 -0400 Subject: [PATCH 6/6] Update README to reflect ms to seconds conversion. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2c8760a..24778e5 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,8 @@ bedrock.start(); For documentation on configuration, see [config.js](./lib/config.js). -`config.session-mongodb.ttl` is a computed property that based off of -`config.express.session.ttl`. In order to change the ttl for sessions you will +`config.session-mongodb.ttl` is a computed property that converts +`config.express.session.ttl` to seconds. In order to change the ttl for sessions you will now need to change the `config.express.session.ttl` using milliseconds. [bedrock]: https://github.com/digitalbazaar/bedrock