-
Notifications
You must be signed in to change notification settings - Fork 5
SK-2528: update jwt-decode library for Node SDK #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import jwt_decode, { JwtPayload } from 'jwt-decode'; | ||
| import { JwtPayload, jwtDecode } from 'jwt-decode'; | ||
| import { MessageType, printLog } from '..'; | ||
| import logs from '../logs'; | ||
|
|
||
|
|
@@ -9,7 +9,7 @@ function isExpired(token: string) { | |
| return true; | ||
| } | ||
| let isJwtExpired = false; | ||
| const decoded: JwtPayload = jwt_decode(token); | ||
| const decoded: JwtPayload = jwtDecode(token); | ||
|
||
| const currentTime = (new Date().getTime() / 1000); | ||
| const expiryTime = decoded.exp; | ||
| if (expiryTime && currentTime > expiryTime) { | ||
|
|
@@ -26,7 +26,7 @@ function isTokenValid(token: string) { | |
| try { | ||
| if (token === "") return false | ||
| let isJwtExpired = false; | ||
| const decoded: JwtPayload = jwt_decode(token); | ||
| const decoded: JwtPayload = jwtDecode(token); | ||
|
||
| const currentTime = (new Date().getTime() / 1000); | ||
| const expiryTime = decoded.exp; | ||
| if (expiryTime && currentTime > expiryTime) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||
| import jwt_decode from 'jwt-decode'; | ||||||||||||
| import { jwtDecode } from 'jwt-decode'; | ||||||||||||
| import { isTokenValid, isExpired } from '../../../../src/utils/jwt-utils'; | ||||||||||||
|
|
||||||||||||
| jest.mock('jwt-decode'); | ||||||||||||
|
||||||||||||
| jest.mock('jwt-decode'); | |
| jest.mock('jwt-decode', () => ({ | |
| __esModule: true, | |
| jwtDecode: jest.fn(), | |
| })); |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a named export (jwtDecode), jest.mock('jwt-decode') may not produce a mocked jwtDecode function in the way this test expects—especially since jwt-decode@4 is ESM-only. This can cause jwtDecode.mockReturnValue / mockImplementation to throw because jwtDecode is not a Jest mock. Prefer providing an explicit Jest mock factory that exports jwtDecode as jest.fn() (and sets __esModule: true when applicable), or use Jest’s ESM mocking APIs if the test environment is ESM.
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a named export (jwtDecode), jest.mock('jwt-decode') may not produce a mocked jwtDecode function in the way this test expects—especially since jwt-decode@4 is ESM-only. This can cause jwtDecode.mockReturnValue / mockImplementation to throw because jwtDecode is not a Jest mock. Prefer providing an explicit Jest mock factory that exports jwtDecode as jest.fn() (and sets __esModule: true when applicable), or use Jest’s ESM mocking APIs if the test environment is ESM.
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a named export (jwtDecode), jest.mock('jwt-decode') may not produce a mocked jwtDecode function in the way this test expects—especially since jwt-decode@4 is ESM-only. This can cause jwtDecode.mockReturnValue / mockImplementation to throw because jwtDecode is not a Jest mock. Prefer providing an explicit Jest mock factory that exports jwtDecode as jest.fn() (and sets __esModule: true when applicable), or use Jest’s ESM mocking APIs if the test environment is ESM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jwt-decode@4is ESM-only. If this Node SDK is published/compiled to CommonJS (common for TS SDKs without\"type\": \"module\"), consumers will hit runtime errors when requiring the SDK (e.g.,ERR_REQUIRE_ESM). If the SDK isn't ESM end-to-end, consider keepingjwt-decodeon a CJS-compatible major (or switching the SDK build/publish output to ESM) before merging this dependency bump.