Skip to content

Fix generateJWT closure capture to use updatable global reference#559

Closed
davidtruong wants to merge 1 commit intomainfrom
claude/fix-issue-160-Cun8F
Closed

Fix generateJWT closure capture to use updatable global reference#559
davidtruong wants to merge 1 commit intomainfrom
claude/fix-issue-160-Cun8F

Conversation

@davidtruong
Copy link
Copy Markdown

The generateJWT callback passed to initialize() was captured in a closure and never updated, causing stale references in React apps where the callback depends on changing state (e.g., rotating user tokens).

Changed all internal references from the closure-captured parameter to the module-level generateJWTGlobal variable, and added a setGenerateJWT() method to the WithJWT interface so users can update the function after initialization without reinitializing the entire SDK.

Also improved the type of generateJWTGlobal from any to a proper type alias (GenerateJWTFunction) for better type safety, and added jest.clearAllTimers() in test beforeEach to fix timer leak between tests.

Fixes #160

https://claude.ai/code/session_01TDMxsnQDkRoXn4181Vrv95

JIRA Ticket(s) if any

Description

Test Steps

The generateJWT callback passed to initialize() was captured in a closure
and never updated, causing stale references in React apps where the
callback depends on changing state (e.g., rotating user tokens).

Changed all internal references from the closure-captured parameter to
the module-level generateJWTGlobal variable, and added a setGenerateJWT()
method to the WithJWT interface so users can update the function after
initialization without reinitializing the entire SDK.

Also improved the type of generateJWTGlobal from `any` to a proper
type alias (GenerateJWTFunction) for better type safety, and added
jest.clearAllTimers() in test beforeEach to fix timer leak between tests.

Fixes #160

https://claude.ai/code/session_01TDMxsnQDkRoXn4181Vrv95
@davidtruong davidtruong requested a review from mprew97 as a code owner April 7, 2026 14:58
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.44%. Comparing base (190a168) to head (bc567d8).

Files with missing lines Patch % Lines
src/authorization/authorization.ts 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #559      +/-   ##
==========================================
- Coverage   74.45%   74.44%   -0.01%     
==========================================
  Files          57       57              
  Lines        2736     2739       +3     
  Branches      798      815      +17     
==========================================
+ Hits         2037     2039       +2     
+ Misses        698      659      -39     
- Partials        1       41      +40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@davidtruong
Copy link
Copy Markdown
Author

Things are fixed

@davidtruong davidtruong closed this Apr 8, 2026
@davidtruong davidtruong deleted the claude/fix-issue-160-Cun8F branch April 8, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

generateJWT method does not respect function changes

3 participants