landry
landry•10mo ago

Add orgId and orgRole to ctx.auth.getUserIdentity()

Is it possible to add org_id and org_role attributes to the user object returned by the ctx.auth.getUserIdentity method when using the ConvexProviderWithClerk component? Currently, the user object lacks these attributes, making it cumbersome to write queries and mutations that depend on the current user's organization. This means that I have to manually provide the orgId returned from Clerks useAuth hook to every query or mutation that depends on the user's organization, which takes away from the ergonomic experience of using Convex with Clerk. The ability to use http actions to keep the db in sync with Clerk has been incredible. This feature would be the cherry on top 🙂 Thank you for considering this feature request!
3 Replies
Michal Srb
Michal Srb•10mo ago
Sounds like you are using webhooks, so you should be able sync and read org_role from your Convex DB. org_id might be a bit trickier, since the user can be in multiple orgs and choose them on the client? You could probably use the custom JWT you set up for Convex to pass the org_id through (in some standard claim like "gender" - we're working on making this easier). If the JWT doesn't work then you might want to use custom useQuery etc. hooks that always get the org ID. Example of this approach is here: https://github.com/get-convex/convex-lucia-auth-demo/blob/main/src/usingSession.tsx
GitHub
convex-lucia-auth-demo/src/usingSession.tsx at main · get-convex/co...
Demo showing authentication powered by Convex and Lucia - get-convex/convex-lucia-auth-demo
landry
landryOP•10mo ago
Okay thank you for your swift response! I'm going to try updating the JWT template in Clerk to include the org_id. I'll post any updates here. Updating the JWT template works!. I’m setting the orgId to gender for now. I will probably do the same for orgRole, since the user’s orgRole can change from org to org. I’m adding the ordId as the key on the ConvexProviderWithClerk component in order to ensure re-renders on org change.
Michal Srb
Michal Srb•7mo ago
Custom claims are now supported with convex@1.14.0

Did you find this page helpful?