Skip to content

Commit 402a34f

Browse files
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 <noreply@anthropic.com>
1 parent 190a168 commit 402a34f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/authorization/authorization.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,21 @@ export function initializeWithConfig(initializeParams: InitializeParams) {
11921192
: initialize(authToken);
11931193
}
11941194

1195+
/**
1196+
* Updates the JWT generator function used by the SDK.
1197+
*
1198+
* This is useful when the outer context that the `generateJWT` callback
1199+
* closes over changes after `initialize()` has already been called
1200+
* (e.g., when an upstream auth token is refreshed).
1201+
*
1202+
* @param newGenerateJWT - A function that returns a Promise resolving to a JWT string.
1203+
*/
1204+
export function setGenerateJWT(
1205+
newGenerateJWT: (payload: GenerateJWTPayload) => Promise<string>
1206+
) {
1207+
generateJWTGlobal = newGenerateJWT;
1208+
}
1209+
11951210
export function setTypeOfAuthForTestingOnly(authType: TypeOfAuth) {
11961211
if (!authType) {
11971212
setTypeOfAuth(null);

0 commit comments

Comments
 (0)