Repository navigation
feat: pass request context to custom cookie signer - #381
Open
SameRainbows wants to merge 1 commit into
Open
SameRainbows wants to merge 1 commit into
SameRainbows wants to merge 1 commit into
Conversation
2 tasks done
This branch has not been deployed
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.
Fixes #289.
Description
When implementing multi-tenant architectures or request-aware signing, a custom signer needs access to the current request (for example, to select tenant-specific secrets based on headers or hostname).
Previously,
signCookieandunsignCookieonly passed the cookie value tosigner.sign(value)andsigner.unsign(value). This PR forwards the request or context as the second parameter:reply.setCookieandreply.signCookie(value)forwardreply.requestrequest.unsignCookie(value)forwardsrequestfastify.signCookie(value, context)andfastify.unsignCookie(value, context)forward the provided contextExisting signers taking one argument remain completely compatible.
Changes
index.js, forward context tosigner.signandsigner.unsign.types/index.d.tsandtypes/index.tst.ts, updateSignerMethodstypings.README.md, add multi-tenant custom signer documentation.test/cookie.test.js, add multi-tenant test suite verifying tenant-based signing and unsigning.Checklist
npm test(58/58 unit tests passing with 100% c8 coverage, 46/46 tstyche tests passing)