Cam
Cam9mo ago

Add headers/tokens to calls to queries and actions

Hi, Can anyone describe how I can ensure additional data is sent in headers when interacting with the backend? I have some security tokens stored on the client that I would like to have access to on the server (for external api requests). I’d like to avoid making these calls from the client if possible, because there will be several subsequent queries and actions to trigger. These are transient, and user specific so I can’t store as env vars on the server. I could store them in a temporary table, and retrieve when needed, but that seems messy and will require a cleanup activity.
2 Replies
lee
lee9mo ago
i would model this as having args that are implicitly passed to the function whenever you do a query/mutation/action, and parsed out of the args into the ctx on the server side. this is the same pattern as useSessionQuery/queryWithSession as implemented in convex-helpers https://www.npmjs.com/package/convex-helpers#session-tracking-via-client-side-sessionid-storage . you can use the package directly or fork the code to pass up multiple fields of arbitrary type.
npm
convex-helpers
A collection of useful code to complement the official convex package.. Latest version: 0.1.36, last published: 6 days ago. Start using convex-helpers in your project by running npm i convex-helpers. There are no other projects in the npm registry using convex-helpers.
Cam
CamOP9mo ago
Awesome, that sounds like a great approach 👍

Did you find this page helpful?