Repository navigation
fix: reply.jwtSign(payload, cb) with a dynamic secret - #440
Merged
mcollina merged 2 commits intoNov 22, 2026
Merged
Conversation
Signed-off-by: Talha Shafeeq <talha.shafeeq.ts@gmail.com>
2 tasks done
Add test verifying reply.jwtSign(payload, null, cb) functions correctly when a dynamic secret callback is configured. Signed-off-by: Talha Shafeeq <talha.shafeeq.ts@gmail.com>
Contributor
Author
|
Thanks @Tony133 and @gurgunday for the review! I have added the requested test for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
reply.jwtSign(payload, cb)is invoked with a dynamic secret function (e.g.(req, payload, cb) => cb(...)orasync (req, payload) => ...),typeof options === 'function'setsuseLocalSigner = falseand callssigner(payload, next).Because the global
signerwas compiled with an asynchronous key fetcher,signer(payload, next)passes FastJwt's internal callback(payload, fastJwtCb)rather than Fastify's expected(request, payload, cb)signature. This leavesrequestomitted and results in an unhandledTypeError: cb is not a function.This fix tracks
hasStaticPrivateKeyand only setsuseLocalSigner = falsewhenhasStaticPrivateKeyis true. For dynamic secret providers,useLocalSignerremainstrueso signing goes throughsteed.waterfallwithsecretCallbackSign(reply.request, payload, callback).Split from #439 as requested by @Tony133 in #438 (comment) (Part 1/3).
Tests
reply.jwtSign(payload, cb)with callback-based dynamic secret function.reply.jwtSign(payload, cb)with async dynamic secret function.tstyche) andeslintpass cleanly.Checklist
npm test(lint, unit tests with 100% coverage, and type tests)