Skip to content

feat: pass request context to custom cookie signer - #381

Open
SameRainbows wants to merge 1 commit into
fastify:mainfrom
SameRainbows:feat/multi-tenant-custom-signer
Open

SameRainbows wants to merge 1 commit into
fastify:mainfrom
SameRainbows:feat/multi-tenant-custom-signer

Conversation

@SameRainbows

Copy link
Copy Markdown

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, signCookie and unsignCookie only passed the cookie value to signer.sign(value) and signer.unsign(value). This PR forwards the request or context as the second parameter:

  • reply.setCookie and reply.signCookie(value) forward reply.request
  • request.unsignCookie(value) forwards request
  • fastify.signCookie(value, context) and fastify.unsignCookie(value, context) forward the provided context

Existing signers taking one argument remain completely compatible.

Changes

  • In index.js, forward context to signer.sign and signer.unsign.
  • In types/index.d.ts and types/index.tst.ts, update SignerMethods typings.
  • In README.md, add multi-tenant custom signer documentation.
  • In test/cookie.test.js, add multi-tenant test suite verifying tenant-based signing and unsigning.

Checklist

  • run npm test (58/58 unit tests passing with 100% c8 coverage, 46/46 tstyche tests passing)
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows the Developer's Certification of Origin

This branch has not been deployed

No deployments
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.

Different cookie secret based on request

1 participant