feat: change default value of unset option from 'keep' to 'destroy' (#1135)

* feat: change default value of unset option from 'keep' to 'destroy' in session middleware

* docs: improve
This commit is contained in:
Sebastian Beltran
2026-07-14 12:33:52 -05:00
committed by GitHub
parent 4630709e3a
commit 0c24bb4c31
4 changed files with 7 additions and 6 deletions
+3 -1
View File
@@ -1,7 +1,6 @@
unreleased
==========
## ⚠️ BREAKING CHANGES
* Change `saveUninitialized` option default from `true` to `false`
@@ -11,6 +10,9 @@ unreleased
* Expire the session cookie on the response when the session is destroyed
- Applies to `req.session.destroy()` and to `unset: 'destroy'`, when the request
came in with a session cookie
* Change `unset` option default from `'keep'` to `'destroy'`
- Sessions unset via `req.session = null` (or `delete`) are now deleted from the store
when the response ends; pass `unset: 'keep'` to restore the previous behavior
## Other changes
+1 -1
View File
@@ -335,7 +335,7 @@ The session store instance, defaults to a new `MemoryStore` instance.
Control the result of unsetting `req.session` (through `delete`, setting to `null`,
etc.).
The default value is `'keep'`.
The default value is `'destroy'`.
- `'destroy'` The session will be destroyed (deleted) when the response ends,
and the response will set an expired cookie to remove it from the client.
+1 -2
View File
@@ -117,8 +117,7 @@ function session(options) {
throw new TypeError('unset option must be "destroy" or "keep"');
}
// TODO: switch to "destroy" on next major
var unsetDestroy = opts.unset === 'destroy'
var unsetDestroy = opts.unset !== 'keep'
if (Array.isArray(secrets) && secrets.length === 0) {
throw new TypeError('secret option array must contain one or more strings');
+2 -2
View File
@@ -1301,7 +1301,7 @@ describe('session()', function(){
assert.throws(session.bind(null, { unset: 'bogus!' }), /unset.*must/)
});
it('should default to keep', function(done){
it('should default to destroy', function(done){
var store = new session.MemoryStore();
var server = createServer({ store: store }, function (req, res) {
req.session.count = req.session.count || 0
@@ -1324,7 +1324,7 @@ describe('session()', function(){
if (err) return done(err);
store.length(function(err, len){
if (err) return done(err);
assert.strictEqual(len, 1)
assert.strictEqual(len, 0)
done();
});
});