Eliot
Eliot3mo ago

Call Internal Functions from Backend

We're using convex in combination with a nodejs backend that handles heavier tasks. We've written a bunch of internal convex functions that we'd also like to call from the backend. Is this possible?
6 Replies
Convex Bot
Convex Bot3mo ago
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!
Clever Tagline
Clever Tagline3mo ago
Those Convex functions could be called either via an HTTP action, or via the HTTP API, whichever makes the most sense for your use case.
erquhart
erquhart3mo ago
Just to clarify, since you specified internal functions, you'll want to use one of the methods Clever Tagline mentioned to call a public function, and use ctx.runQuery/Mutation/Action in the public function to call the internal functions. Make sure to avoid sequential ctx.run calls.
Eliot
EliotOP3mo ago
But this would still require implementing our own auth layer, right? We have RLS setup so I was trying to figure out if there was a way to directly call the "internal" actions through the official SDK & a token of some kind (i.e. convex.mutation(internal.abc.def)) instead of just implementing our own "ADMIN" auth token and checking that, etc.
erquhart
erquhart3mo ago
The official sdk handles client to server auth, but has no prescriptions for server to server. Many use a shared secret.
Clever Tagline
Clever Tagline3mo ago
That's what I do for all of our HTTP endpoints: pass a token via a Bearer header, then compare against an environment variable, with a different variable value on dev vs prod. All HTTP endpoints use a wrapper that does the token check before running the main logic, and it works really well.

Did you find this page helpful?