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
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.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.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.Got it, good to know! Thank you 🙂