From 0546c1165d8b33fd404332adc49691d5a12416da Mon Sep 17 00:00:00 2001 From: es3 Date: Fri, 11 Oct 2019 03:53:01 -0400 Subject: [PATCH 1/5] Add setPromise to this.req.sessionStore Add Promise type object for use as Promise return in req.session.save() --- session/session.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session/session.js b/session/session.js index fee7608c..e76147ef 100644 --- a/session/session.js +++ b/session/session.js @@ -69,7 +69,7 @@ defineMethod(Session.prototype, 'resetMaxAge', function resetMaxAge() { */ defineMethod(Session.prototype, 'save', function save(fn) { - this.req.sessionStore.set(this.id, this, fn || function(){}); + this.req.sessionStore.setPromise = this.req.sessionStore.set(this.id, this, fn || function(){}) return this; }); From 0a27782df6912b688f597ea1dffd818f2cc02437 Mon Sep 17 00:00:00 2001 From: es3 Date: Fri, 11 Oct 2019 04:01:55 -0400 Subject: [PATCH 2/5] Add Promise return to req.session.save() Now we can use req.session.save() function as promise example await req.session.save() .then(()=>{ console.log('saved') }) .catch(()=>{ console.log('error') }) --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 24221b48..73d89ad8 100644 --- a/index.js +++ b/index.js @@ -393,6 +393,7 @@ function session(options) { debug('saving %s', this.id); savedHash = hash(this); _save.apply(this, arguments); + return this.req.sessionStore.setPromise } Object.defineProperty(sess, 'reload', { From 8147b3e4cc2b3298b08f0c4d2cbd9e3a91c97918 Mon Sep 17 00:00:00 2001 From: es3 Date: Fri, 11 Oct 2019 04:08:42 -0400 Subject: [PATCH 3/5] Update session.js --- session/session.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session/session.js b/session/session.js index e76147ef..2009773e 100644 --- a/session/session.js +++ b/session/session.js @@ -69,7 +69,7 @@ defineMethod(Session.prototype, 'resetMaxAge', function resetMaxAge() { */ defineMethod(Session.prototype, 'save', function save(fn) { - this.req.sessionStore.setPromise = this.req.sessionStore.set(this.id, this, fn || function(){}) + this.req.sessionStore.setPromise = this.req.sessionStore.set(this.id, this, fn || function(){}); return this; }); From 580e0bdb3bc9a28c97472737abab349c8587d5c9 Mon Sep 17 00:00:00 2001 From: es3 Date: Fri, 11 Oct 2019 04:11:01 -0400 Subject: [PATCH 4/5] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 73d89ad8..3e7aed95 100644 --- a/index.js +++ b/index.js @@ -393,7 +393,7 @@ function session(options) { debug('saving %s', this.id); savedHash = hash(this); _save.apply(this, arguments); - return this.req.sessionStore.setPromise + return this.req.sessionStore.setPromise; } Object.defineProperty(sess, 'reload', { From 1e4760f26ea2ddcb8003aa7449b854b4cf7e4b95 Mon Sep 17 00:00:00 2001 From: es3 Date: Fri, 11 Oct 2019 06:51:41 -0400 Subject: [PATCH 5/5] Doc: Promise append to save() function --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index a1ed3fa1..ac2955a9 100644 --- a/README.md +++ b/README.md @@ -368,6 +368,18 @@ req.session.save(function(err) { }) ``` +#### Session.save().then(callback) + +You can use Promise type as return + +Example +```js +await req.session.save() +.then(()=>{ + // session saved +}) +``` + #### Session.touch() Updates the `.maxAge` property. Typically this is