[Question] How to globally add context (e.g., user locale) to all requests? #20
Replies: 1 comment 1 reply
-
|
Hey @aleksolutions, Currently, forge-trpc does not provide anything beyond the basics. The main reason is that this may introduce opinions on technology choices incompatible with everyone's stack. I assume you want to pass the locale along because you do not get this from the Forge resolver context. I think, if this is a common use case, we can consider adding a package to provide helpers. However, I would only do this if there is a strong indication that many library users will use it. In our Forge code, we have a few validation helpers for the Forge resolver context and further tRPC middleware to filter requests based on what the RPC route is supposed to allow or block. For example, we have middleware to whitelist the Forge modules from which an RPC route can be called, or a middleware to validate permissions against the user associated with the request. Some of these middlewares could be published as a separate package, provided they remain mostly technology-neutral (apart from what we already have). For example, Forge context validation middleware could be implemented with Standard Schema, which seems to be becoming the go-to abstraction for schema validation libraries. I would be curious to hear from others if you have similar use cases. What's the general opinion on this? Would this be useful, or should this project remain focused on just offering the basics? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi team,
First off, thanks for the great work on
forge-trpc- it's significantly improved our development experience!I have a question regarding requests: Is there a recommended way to automatically include additional context, specifically the user's locale, with every request? The goal is to access this locale within the server-side context/handler for each mutation.
Currently, I'm passing the locale manually with each call. I'm wondering if there's a cleaner, global approach, perhaps by extending a shared context or using some form of middleware provided by the adapter.
Thanks for any guidance!
Beta Was this translation helpful? Give feedback.
All reactions