Socket
Socket
Sign inDemoInstall

koa-session

Package Overview
Dependencies
Maintainers
8
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-session - npm Package Compare versions

Comparing version 4.7.1 to 4.8.0

9

History.md
4.8.0 / 2018-01-17
==================
**features**
* [[`ca6b329`](http://github.com/koajs/session/commit/ca6b32906678b3cf6168c4afac250b2e68fd17c8)] - feat: support opts.renew (#111) (Yiyu He <<dead_horse@qq.com>>)
**fixes**
* [[`5c2fc72`](http://github.com/koajs/session/commit/5c2fc72cab47450da2c9ae8fedba8657d0c264ee)] - fix: ensure store expired after cookie (dead-horse <<dead_horse@qq.com>>)
4.7.1 / 2018-01-11

@@ -3,0 +12,0 @@ ==================

50

lib/context.js

@@ -210,3 +210,2 @@ 'use strict';

const session = this.session;
const prevHash = this.prevHash;
const opts = this.opts;

@@ -224,12 +223,5 @@ const ctx = this.ctx;

// force save session when `session._requireSave` set
let changed = true;
if (!session._requireSave) {
const json = session.toJSON();
// do nothing if new and not populated
if (!prevHash && !Object.keys(json).length) return;
changed = prevHash !== util.hash(json);
// do nothing if not changed and not in rolling mode
if (!this.opts.rolling && !changed) return;
}
const reason = this._shouldSaveSession();
debug('should save session: %s', reason);
if (!reason) return;

@@ -240,5 +232,35 @@ if (typeof opts.beforeSave === 'function') {

}
const changed = reason === 'changed';
yield this.save(changed);
}
_shouldSaveSession() {
const prevHash = this.prevHash;
const session = this.session;
// force save session when `session._requireSave` set
if (session._requireSave) return 'force';
// do nothing if new and not populated
const json = session.toJSON();
if (!prevHash && !Object.keys(json).length) return '';
// save if session changed
const changed = prevHash !== util.hash(json);
if (changed) return 'changed';
// save if opts.rolling set
if (this.opts.rolling) return 'rolling';
// save if opts.renew and session will expired
if (this.opts.renew) {
const expire = session._expire;
const maxAge = session.maxAge;
// renew when session will expired in maxAge / 2
if (expire && maxAge && expire - Date.now() < maxAge / 2) return 'renew';
}
return '';
}
/**

@@ -270,3 +292,3 @@ * remove session

// set expire for check
const maxAge = opts.maxAge ? opts.maxAge : ONE_DAY;
let maxAge = opts.maxAge ? opts.maxAge : ONE_DAY;
if (maxAge === 'session') {

@@ -285,2 +307,6 @@ // do not set _expire in json if maxAge is set to 'session'

debug('save %j to external key %s', json, externalKey);
if (typeof maxAge === 'number') {
// ensure store expired after cookie
maxAge += 10000;
}
yield this.store.set(externalKey, json, maxAge, {

@@ -287,0 +313,0 @@ changed,

@@ -5,3 +5,3 @@ {

"repository": "koajs/session",
"version": "4.7.1",
"version": "4.8.0",
"keywords": [

@@ -23,3 +23,4 @@ "koa",

"mm": "^2.1.0",
"mocha": "3 ",
"mocha": "3",
"mz-modules": "^2.0.0",
"should": "8",

@@ -26,0 +27,0 @@ "supertest": "2"

@@ -59,3 +59,4 @@ # koa-session

signed: true, /** (boolean) signed or not (default true) */
rolling: false, /** (boolean) Force a session identifier cookie to be set on every response. The expiration is reset to the original maxAge, resetting the expiration countdown. default is false **/
rolling: false, /** (boolean) Force a session identifier cookie to be set on every response. The expiration is reset to the original maxAge, resetting the expiration countdown. (default is false) */
renew: false, /** (boolean) renew session when session is nearly expired, so we can always keep user logged in. (default is false)*/
};

@@ -62,0 +63,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc