diff --git a/Readme.md b/Readme.md index 6a00431..0351509 100644 --- a/Readme.md +++ b/Readme.md @@ -33,7 +33,7 @@ ## Installation ```js -$ npm install koa-session +$ npm install @viegg/koa-session ``` ## Example @@ -41,7 +41,7 @@ $ npm install koa-session View counter example: ```js -const session = require('koa-session'); +const session = require('@viegg/koa-session'); const Koa = require('koa'); const app = new Koa(); @@ -113,7 +113,7 @@ console.log('listening on port 3000'); Once you pass `options.store`, session storage is dependent on your external store -- you can't access the session if your external store is down. **Use external session stores only if necessary, avoid using session as a cache, keep the session lean, and store it in a cookie if possible!** - The way of generating external session id is controlled by the `options.genid`, which defaults to `Date.now() + '-' + uid.sync(24)`. + The way of generating external session id is controlled by the `options.genid`, which defaults to `ctx => Date.now() + '-' + uid.sync(24)`. If you want to add prefix for all external session id, you can use `options.prefix`, it will not work if `options.genid` present. diff --git a/lib/context.js b/lib/context.js index 410996b..9edd6ba 100644 --- a/lib/context.js +++ b/lib/context.js @@ -202,7 +202,7 @@ class ContextSession { create(val, externalKey) { debug('create session with val: %j externalKey: %s', val, externalKey); - if (this.store) this.externalKey = externalKey || this.opts.genid(); + if (this.store) this.externalKey = externalKey || this.opts.genid(this.ctx); this.session = new Session(this, val); } diff --git a/package.json b/package.json index ff25fb3..e759353 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "koa-session", + "name": "@viegg/koa-session", "description": "Koa cookie session middleware with external store support", - "repository": "koajs/session", - "version": "5.10.1", + "repository": "iwestlin/session", + "version": "5.10.3", "keywords": [ "koa", "middleware",