Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
unreleased
==========


## ⚠️ BREAKING CHANGES

* Change `saveUninitialized` option default from `true` to `false`
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions test/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
});
});
Expand Down
Loading