Eliot GeversE
Convex Community6mo ago
7 replies
Eliot Gevers

Interact with Convex from Nextjs Backend, securely and minimal

My Nextjs backend needs to interact with Convex a lot and I want to ask what the best patterns are. I want my convex functions to know: "This request is coming from our nextjs backend so it's good, let's continue"

Currently I am passing {token} to fetchQueries and fetchMutations but this is annoying because I have to pass around that token all the time. It also means I need an authenticated user, or I need to remove auth-check from my endpoint. (token can also only be generated in pages/routes/server actions, so I cant use Convex in util functions without passing that token around all the time...)

Another option would be to use an SECRET_KEY on both ends, but that means I would need to pass that into the arguments and my SECRET_KEY would be logged in history in the dashboard, I dont like that approach.

I feel like we need a better, officially recommended method/helper here. Before, I was using Drizzle so I had direct access to my database on the nextjs backend. This made it very easy to just get data anywhere. I need some helper to do operations on the serverside directly to convex, and convex needs to know that the request came from my nextjs backend.

Looking forward to hearing all your thoughts!
Was this page helpful?