Extra user metadata in auth ctx (for clerk)
I've hooked up clerk to my convex project.
In the auth ctx, it seems like only a few fields are available here: https://docs.convex.dev/auth/functions-auth#user-identity-fields
Is it possible to pass in custom user meta data into the auth ctx for functions? https://clerk.com/docs/users/user-metadata
User metadata | Clerk
User objects hold a set of metadata that can be used internally to store arbitrary information.
Auth in Functions | Convex Developer Hub
Within a Convex function, you can access information
8 Replies
The full list of "supported" fields is in the link at the the end of the text you linked: https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims
You can use any of those names to pass in data through the Claims on your JWT Token, but it has to be one of the fields supported by Clerk. The list of fields supported in JWT tokens and in Clerk's JS client differs, if you want another field you can ask Clerk on Discord to add it.
Final: OpenID Connect Core 1.0 incorporating errata set 1
OpenID Connect Core 1.0 incorporating errata set 1
Yeah I saw that. I was hoping to not have to stuff data into one of those fields though. It will make it tough to understand why I did that in a couple of months.
Could it be an option for you to store the user metadata directly in the Convex database? https://docs.convex.dev/auth/database-auth
Storing Users in the Convex Database | Convex Developer Hub
You might want to have a centralized place that stores information about the
Yeah it could. I'm not happy with having to do a lookup each function call though. I'm guessing that'll get expensive.
Fetching data from the database in each call is very cheap- on the order of single digit milliseconds, and can be parallelized. Is that the part you’re worried about? Or keeping the database in sync with Clerk?
@Nicolas you still need to pipe the information through the JWT Token Claims, otherwise you cannot trust it (unless it's information you'd be OK for the user to spoof).
@ian , it was mostly cost (time and money costs). I was worried about this incurring extra function calls against my quota.
gotcha. The extra db lookups won’t add to the function call count, and the time should be negligible.