koa-generic-session
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -45,3 +45,3 @@ 'use strict'; | ||
* - [`store`] session store instance, default to MemoryStore | ||
* - [`ttl`] store ttl in `ms`, default to oneday | ||
* - [`ttl`] store ttl in `ms`, default to cookie maxAge/expires | ||
* - [`prefix`] session prefix for store, defaulting to `koa:sess:` | ||
@@ -48,0 +48,0 @@ * - [`cookie`] session cookie settings, defaulting to |
@@ -64,3 +64,3 @@ /**! | ||
return _asyncToGenerator(function* () { | ||
let ttl = _this2.options.ttl; | ||
let ttl = typeof _this2.options.ttl === 'function' ? _this2.options.ttl(sess) : _this2.options.ttl; | ||
if (!ttl) { | ||
@@ -67,0 +67,0 @@ const maxAge = sess.cookie && sess.cookie.maxAge; |
@@ -5,3 +5,3 @@ { | ||
"repository": "koajs/generic-session", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "engines": { |
@@ -99,3 +99,3 @@ generic-session | ||
* `prefix`: session prefix for store, defaulting to `koa:sess:`. | ||
* `ttl`: ttl is for sessionStore's expiration time. it is different with `cookie.maxAge`, default to null(means get ttl from `cookie.maxAge`). | ||
* `ttl`: ttl is for sessionStore's expiration time (not to be confused with cookie expiration which is controlled by `cookie.maxAge`), can be a number or a function that returns a number (for dynamic TTL), default to null (means get ttl from `cookie.maxAge` or `cookie.expires`). | ||
* `rolling`: rolling session, always reset the cookie and sessions, defaults to `false`. | ||
@@ -129,2 +129,15 @@ * `genSid`: default sid was generated by [uid2](https://github.com/coreh/uid2), you can pass a function to replace it (supports promises/async functions). | ||
If your application requires dynamic expiration, control `cookie.maxAge` using `ctx.session.cookie.maxAge = dynamicMaxAge`, when you need `ttl` to differ from `cookie.maxAge` (a common example is browser-session cookies having `cookie.maxAge = null`, but you want them to not live indefinitely in the store) specify a function for `ttl`: | ||
```js | ||
{ | ||
ttl: (session) => { | ||
// Expire browser-session cookies from the store after 1 day | ||
if (session.cookie?.maxAge === null) { | ||
return 1000 * 60 * 60 * 24; | ||
} | ||
} | ||
} | ||
``` | ||
## Hooks | ||
@@ -131,0 +144,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36722
195