From 465ff7d30472f427cbb5900cc448bbb3c3ba3f7f Mon Sep 17 00:00:00 2001 From: "Prioregroup.com" Date: Sat, 26 May 2018 00:44:26 +0200 Subject: [PATCH] token expired callback --- lib/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index f5da77fc..c2e3b17e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -25,6 +25,7 @@ module.exports = function(options) { secretCallback = wrapStaticSecretInCallback(secretCallback); } + var isExpiredCallback = options.isExpired; var isRevokedCallback = options.isRevoked || DEFAULT_REVOKED_FUNCTION; var _requestProperty = options.userProperty || options.requestProperty || 'user'; @@ -99,7 +100,19 @@ module.exports = function(options) { function verifyToken(secret, callback) { jwt.verify(token, secret, options, function(err, decoded) { if (err) { - callback(new UnauthorizedError('invalid_token', err)); + if (err.message === 'jwt expired' && isFunction(isExpiredCallback)) { + set(req, _requestProperty, dtoken.payload); + isExpiredCallback(err, req, function (err) { + if (err) { + callback(new UnauthorizedError('invalid_token', err)); + } else { + _decoded = jwt.decode(token); + callback(null, _decoded) + } + }); + } else { + callback(new UnauthorizedError('invalid_token', err)); + } } else { callback(null, decoded); }