From 42cd110444866b784b82558ca988fcad99ade484 Mon Sep 17 00:00:00 2001 From: P-1000 Date: Sun, 1 Oct 2023 12:42:26 +0530 Subject: [PATCH 1/3] ()feat)Implemented a new feature in the function to check the expiration time of JWTs --- .vscode/settings.json | 3 +++ src/index.js | 1 + src/lib/isJWTExpiration.js | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 src/lib/isJWTExpiration.js diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..30de70fe7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.acceptSuggestionOnEnter": "on" +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index bef4cfff4..76c3b2c91 100644 --- a/src/index.js +++ b/src/index.js @@ -55,6 +55,7 @@ import isBIC from './lib/isBIC'; import isMD5 from './lib/isMD5'; import isHash from './lib/isHash'; import isJWT from './lib/isJWT'; +import isJWTExpiration from './lib/isJWTExpiration'; import isJSON from './lib/isJSON'; import isEmpty from './lib/isEmpty'; diff --git a/src/lib/isJWTExpiration.js b/src/lib/isJWTExpiration.js new file mode 100644 index 000000000..1b05cd112 --- /dev/null +++ b/src/lib/isJWTExpiration.js @@ -0,0 +1,20 @@ +export default function isJWTExpiration(token) { + if (!token || typeof token !== 'string') { + return false; + } + try { + + const payload = JSON.parse(atob(token.split('.')[1])); + + if (payload.exp && typeof payload.exp === 'number') { + const currentTimestamp = Math.floor(Date.now() / 1000); + return payload.exp >= currentTimestamp; + } + + return false; + } catch (error) { + console.error("Error parsing JWT payload:", error.message); + return false; + } + } + \ No newline at end of file From 8208c27c2d8cbc8aa51be520706b38b218103bcd Mon Sep 17 00:00:00 2001 From: P-1000 Date: Sun, 1 Oct 2023 12:47:54 +0530 Subject: [PATCH 2/3] (feat)Implemented a new feature in the function to check the expiration time of JWTs --- src/lib/isJWTExpiration.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/isJWTExpiration.js b/src/lib/isJWTExpiration.js index 1b05cd112..b50274c69 100644 --- a/src/lib/isJWTExpiration.js +++ b/src/lib/isJWTExpiration.js @@ -13,7 +13,6 @@ export default function isJWTExpiration(token) { return false; } catch (error) { - console.error("Error parsing JWT payload:", error.message); return false; } } From 598b8d8e51e50aa730dbaf8fe4a372ba8e7d9c6e Mon Sep 17 00:00:00 2001 From: P-1000 Date: Sun, 1 Oct 2023 13:06:24 +0530 Subject: [PATCH 3/3] (feat)Implemented a new feature in the function to check the expiration time of JWTs --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 76c3b2c91..fbd77d3a1 100644 --- a/src/index.js +++ b/src/index.js @@ -178,6 +178,7 @@ const validator = { isMD5, isHash, isJWT, + isJWTExpiration, isJSON, isEmpty, isLength,