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 5.7.1 to 5.8.0

6

History.md
5.8.0 / 2018-01-17
==================
**features**
* [[`bb5f4bf`](http://github.com/koajs/session/commit/bb5f4bf86da802cb37cd5e3a990b5bbcc4f6d144)] - feat: support opts.renew (#111) (Yiyu He <<dead_horse@qq.com>>)
5.7.1 / 2018-01-11

@@ -3,0 +9,0 @@ ==================

44

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';
await 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;
// renew when session will expired in maxAge / 2
if (!expire || expire - Date.now() > session.maxAge / 2) return '';
return 'renew';
}
return '';
}
/**

@@ -245,0 +267,0 @@ * remove session

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

"repository": "koajs/session",
"version": "5.7.1",
"version": "5.8.0",
"keywords": [

@@ -24,2 +24,3 @@ "koa",

"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