How to properly combine a Convex query with an action?
I'm trying to implement a query that needs to fetch some encrypted data and decrypt it using AWS KMS. However, I'm running into a TypeScript error where ctx.runAction is not available in the query context. Here's a simplified version of what I'm trying to do:
is the only option to do useEffect in the front end component?
7 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Yeah you'll want to run the action when the query changes, both from the client. An updatedAt timestamp field on the table with the encrypted data would help, so you can just query that and run the effect when it changes.
thanks! this seems kinda messy 😦
I can see that. But if you're fetching data on the server and you cannot store it anywhere due to it's sensitive nature, I don't know how much cleaner you're going to get than this in any reactive framework.
If the reactivity isn't important you could just run an action to get everything at once, but guessing you want it reactive
if i dont want it to be reactive, can i run the action without storing the decrypted data in the table for fetching?
Yep, you would call the action from the client, and in the action you can
await ctx.runQuery()
for the encrypted data, decrypt it, and return
queries can't await actions but actions can await anythinggot it. thanks!