valashnez
valashnez•8mo ago

Running an internal mutation from nodejs backend

Is it possible to run a mutation from the backend? I have a chat app with Clerk set up for authentication. However, I want to periodically send a message as a user when one of my backend services is triggered, but since this occurs on the backend, there is no authed user, so the mutation is failing. Is it possible to override auth for an internal mutation?
4 Replies
ballingt
ballingt•8mo ago
Yep, you can run mutations from the backend with ConvexHttpClient or ConvexClient. "override auth" sounds like you want to pretend to be this user for the purposes of ctx.auth.getUserIdentity() calls? How are you identifying the user? It sounds easier to write an internal mutation, or simpler to write a mutation that takes an extra argument of a secret that only your server knows, to send a message from a user. But there's not need to fake their identity to do this, you can just write another mutation.
valashnez
valashnezOP•8mo ago
Ah, I see. Is there a difference between the ConvexHttpClient and the ConvexClient? Since they're both imported from convex/browser, I thought they couldn't be used from the server.
ballingt
ballingt•8mo ago
Ah that is confusing, if we renamed it it would be convex/client The difference is that ConvexHttpClient uses HTTP requests (useful for doing a single request) while ConvexClient opens a WebSocket and can use subscriptions.
valashnez
valashnezOP•8mo ago
Got it, good to know! Thank you 🙂

Did you find this page helpful?