From 402a34f5af8a7c3e49ba5241ef2803256db1d68f Mon Sep 17 00:00:00 2001 From: Franco Zalamena Date: Tue, 7 Apr 2026 16:00:48 +0100 Subject: [PATCH] Add setGenerateJWT method to update JWT generator after initialization When using JWT auth, the generateJWT function passed to initialize() gets captured and never updates. This adds a setGenerateJWT export that allows updating the function reference at any time, fixing #160. Co-Authored-By: Claude Opus 4.6 --- src/authorization/authorization.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/authorization/authorization.ts b/src/authorization/authorization.ts index 24a6bdb7..1d35f5cd 100644 --- a/src/authorization/authorization.ts +++ b/src/authorization/authorization.ts @@ -1192,6 +1192,21 @@ export function initializeWithConfig(initializeParams: InitializeParams) { : initialize(authToken); } +/** + * Updates the JWT generator function used by the SDK. + * + * This is useful when the outer context that the `generateJWT` callback + * closes over changes after `initialize()` has already been called + * (e.g., when an upstream auth token is refreshed). + * + * @param newGenerateJWT - A function that returns a Promise resolving to a JWT string. + */ +export function setGenerateJWT( + newGenerateJWT: (payload: GenerateJWTPayload) => Promise +) { + generateJWTGlobal = newGenerateJWT; +} + export function setTypeOfAuthForTestingOnly(authType: TypeOfAuth) { if (!authType) { setTypeOfAuth(null);