Skip to content

Commit 282d3af

Browse files
committed
Make the session-mongodb.ttl a computed config value.
1 parent 23b27f6 commit 282d3af

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
### Changed
66
- Update to `connect-mongo@5`.
7+
- Make the `session-mongodb.ttl` config value default to a value computed
8+
from `express.session.ttl`. This does not change the default of 30
9+
minutes but it does allow the express session TTL to properly propagate
10+
to the `MongoStore` session store instance w/o the need for setting
11+
the `session-mongodb.ttl` configuration value independently. It can
12+
still be set independently, overiding the computed value if desired.
713

814
## 6.0.0 - 2022-04-29
915

lib/config.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
/*!
2-
* Copyright (c) 2012-2022 Digital Bazaar, Inc. All rights reserved.
2+
* Copyright (c) 2012-2025 Digital Bazaar, Inc. All rights reserved.
33
*/
4-
import {config} from '@bedrock/core';
4+
import {config, util} from '@bedrock/core';
5+
import '@bedrock/express';
6+
7+
const cc = util.config.main.computer();
58

69
config['session-mongodb'] = {
7-
collection: 'session',
8-
// timeout is in seconds (time for session to live on the server)
9-
ttl: 60 * 30
10+
collection: 'session'
1011
};
12+
13+
// create computed `ttl` property based on express config...
14+
15+
// default to 30 minute TTL expressed in seconds
16+
const THIRTY_MINUTES = 60 * 30;
17+
18+
// timeout is in seconds (time for session to live on the server)
19+
cc('session-mongodb.ttl', () => {
20+
if(config.express?.session) {
21+
// express session ttl is in milliseconds, convert to seconds
22+
const {ttl = THIRTY_MINUTES * 1000} = config.express.session;
23+
// round down to ensure session doesn't live beyond configured value
24+
return Math.floor(ttl / 1000);
25+
}
26+
return THIRTY_MINUTES;
27+
});

0 commit comments

Comments
 (0)