Setting auth on the server
I'm currently using NextJS, tRPC and Clerk to handle some logic outside of convex. Is it possible to set authentication values on the server?
I'm using the
convex.setAuth
function w/ the Clerk token but I'm running into the following error whenever I try to call a convex function (with or without an auth middleware):
15 Replies
What do your server-side Convex calls look like, are you using the HTTP client?
@Chad Maycumber if you could share the code that calls
convex.setAuth
that might help us help you as well, thanks!Yeah definitely! One second

This then gets passed as a context value through tRPC so I can use it in the routes
If you're using our Clerk provider, you shouldn't need to be calling setAuth: https://docs.convex.dev/auth/clerk
If you're going a custom route, then you can check out:
https://docs.convex.dev/auth/custom-auth
at a glance, the setAuth should take in a function, not a value: https://docs.convex.dev/api/classes/react.ConvexReactClient#setauth
Convex Clerk | Convex Developer Hub
Clerk is an authentication platform providing login via
Custom Auth Integration | Convex Developer Hub
Convex can be integrated with any identity provider supporting the
Class: ConvexReactClient | Convex Developer Hub
react.ConvexReactClient
Thanks for the resources I'll give these a shot
From you screenshot it looks like you're not on the latest version of Convex? There have been many fixes to Auth recently. setAuth should take an async function in the latest version - but ideally as Ian suggested you want to use
ConvexProviderWithClerk
instead. Let us know how it goesI'm on convex v13! I think the types for ConvexHTTPClient and the react client might be different? I can't use the Clerk provider here because I need the auth set in an HTTP request!
Thanks for the help here
Ah, gotcha. In that case I would double/triple check that you have the correct combo of Publishable Key, Issuer URL and "convex" set up: The first in the Clerk provider and the latter two in convex.json (and deployed via
convex dev
or convex deploy
).I'm using it in combination with the Clerk provider and that one does seem to function fine passing the auth properly to the convex backend
Hey @Chad Maycumber did you verify that
convex.json
has the right issuer URL in domain
and applicationID: "convex"
in the authInfo
field?It does look like my issuers are correct, I do have two objects in the authInfo field (one for prod; one for dev).
Looking again at the screenshot above, the issue might be that
getToken()
should be getToken({ template: "convex")
I think this is working for me now thanks!