From 80992dbec9733f0e38ce07cf5871eb430fda6bf4 Mon Sep 17 00:00:00 2001 From: Yevhenii Medvedev Date: Wed, 7 Apr 2021 20:58:39 +0300 Subject: [PATCH] fix callback error with promise --- lib/strategy.js | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/lib/strategy.js b/lib/strategy.js index 5834d5e..08d3988 100755 --- a/lib/strategy.js +++ b/lib/strategy.js @@ -45,8 +45,11 @@ class CognitoExpress { }); } - validate(token, callback) { - const p = this.promise.then(() => { + validate(token, callback = (err, result) => new Promise((resolve, reject) => { + if (err) reject(err); + resolve(result); + })) { + return this.promise.then(() => { let decodedJwt = jwt.decode(token, { complete: true }); if (!decodedJwt) return callback(`Not a valid JWT token`, null); @@ -68,26 +71,9 @@ class CognitoExpress { iss: this.iss, maxAge: this.tokenExpiration }; - - if (callback) { - jwtVerify(params, callback); - } else { - return new Promise((resolve, reject) => { - jwtVerify(params, (err, result) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - } + return jwtVerify(params, callback); }); - - if (!callback) { - return p; - } - } + } } function configurationIsCorrect(config) {