Skip to content

Commit

Permalink
feat: allow TTL to be set dynamically (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejose19 authored Jan 10, 2022
1 parent 202fa7d commit 805dc47
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const defaultCookie = {
* @param {Object} options
* - [`key`] cookie name, defaulting to `koa.sid`
* - [`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:`
* - [`cookie`] session cookie settings, defaulting to
* {path: '/', httpOnly: true, maxAge: null, overwrite: true, signed: true}
Expand Down
2 changes: 1 addition & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Store extends EventEmitter {
}

async set(sid, sess) {
let ttl = this.options.ttl
let ttl = typeof this.options.ttl === 'function' ? this.options.ttl(sess) : this.options.ttl;
if (!ttl) {
const maxAge = sess.cookie && sess.cookie.maxAge
if (typeof maxAge === 'number') {
Expand Down

0 comments on commit 805dc47

Please sign in to comment.