Amal ChandranA
Convex Community3mo ago
10 replies
Amal Chandran

Call convex from a Node.js backend using service authentication

Hi, I need to call Convex from a Node.js backend using service authentication (per https://docs.convex.dev/auth#service-authentication).

What's the recommended way to use the admin key in the Node.js client? Do I have to pass it as an argument to every query/mutation, or can I set it once when initializing the client to avoid boilerplate?

I also noticed the internal setAdminAuth function. Is that intended for this use case?

I've identified a few potential approaches:

Using convex-better-auth: Generate an admin API key, use it to fetch a session token, and set that token in the Node.js client. (since im already using https://github.com/get-convex/better-auth)

Using Custom JWTs: Configure custom JWT authentication as per the docs, generate a long-lived token for my service, and pass it using setAuth().

Static Key (Less Ideal): Pass the CONVEX_API_KEY as an argument to every individual query/mutation, which seems verbose.
Add authentication to your Convex app.
Authentication | Convex Developer Hub
Was this page helpful?