Authed Http Actions
Are there any best practices for authenticating http actions?
I'm currently using clerk. I can grab a token from clerk on the F/E. Any recommendations on how to verify/use that token on the B/E?
13 Replies
I believe setting the
Authorization
header to Bearer <clerk token>
should mean that ctx.auth.getUserIdentity()
within the HTTP action returns the user identity for the corresponding clerk user?Ooh awesome! So we kinda get that for free? I’ll play around with it 🙏
Let me know if it works / if you run into any issues! I haven't tried this for a while
Is this documented anywhere? Just for future reference?
We’ll work on documenting this soon. I’ll post here when the docs have been upgraded.
I've tried pulling this out of the auth in the ctx but I don't think this is currently working.
So on my F/E (with clerk), I'm currently using https://clerk.com/docs/request-authentication/cross-origin#using-fetch-with-react
Cross-Origin Requests | Clerk
This guide presents various ways to make authenticated cross-origin requests to the backend using the Clerk SDK.
When I observe the token that's passed into the websocket for convex and the token generated by "useAuth" I notice a difference
The JWT headers are the same
But the JWT payload differs:
The auth token I see in the websocket for convex:
When I directly call
getToken
from useAuth
from Clerk's react lib:
I think I've seen separate network requests to clerk for each of these tokens
Okay, what token should I use in order to get the auth context to include the user correctly?
Another thing I should add, I can see the auth header in the http action. I can pull that out of the request.hearers. So I’m sure that it’s getting passed in
I'm not sure, does
getToken()
take arguments? We call a similar one with template: "convex"
https://github.com/get-convex/convex-js/blob/541ca6507a5d62b38f46de967db220b0edabebaf/src/react-clerk/ConvexProviderWithClerk.tsx#L63-L66@ballingt is right, you need to call clerk with the correct arguments to get your token using the JWT template you set up.
Okay, this was the token call I made on the f/e in order to successfully get the user in the auth context:
Thanks everyone for your help! 🙏