Oscar Gallo
Oscar Gallo•6d ago

I was doing some Convex shaneningans

I was doing some Convex shaneningans today, and it took me a second.... but, is there a way to pass the active organization from Clerk to Convex auth so I can access it from the context?
16 Replies
Sara
Sara•6d ago
Are you looking to migrate to convex auth? or just wondering if you can pass things down the ctx?
Oscar Gallo
Oscar GalloOP•6d ago
The second one. I'm using Clerk and I connected it to Clerk, but I would like to have the organizations available for some validations, specially the active organization
Sara
Sara•6d ago
npm
convex-helpers
A collection of useful code to complement the official convex package.. Latest version: 0.1.104, last published: 19 days ago. Start using convex-helpers in your project by running npm i convex-helpers. There are 20 other projects in the npm registry using convex-helpers.
Sara
Sara•6d ago
this might help Ah, I don't have prior knowledge about that!
erquhart
erquhart•6d ago
It should be in the o claim on the jwt: https://clerk.com/docs/backend-requests/resources/session-tokens So you should be able to do
const identity = await ctx.auth.getUserIdentity();
const activeOrgId = identity.o?.id
const identity = await ctx.auth.getUserIdentity();
const activeOrgId = identity.o?.id
May depend on jwt claims setup in your Clerk dashboard and whether or not you'r using v2 session token claims
Oscar Gallo
Oscar GalloOP•6d ago
Mmm looks like identity doesn't have an o value, maybe that's just the autocomplete
erquhart
erquhart•6d ago
Yeah maybe log it and see, might just be types
Oscar Gallo
Oscar GalloOP•6d ago
Ok, nope, it comes back undefined 😩
erquhart
erquhart•6d ago
Hit your Clerk dashboard and check out your jwt template settings It looks like you need to set which values are included. What I don't know for sure is whether any claims get stripped off coming through Convex. I believe custom claims has been a solved problem for some time though, so it should work.
Oscar Gallo
Oscar GalloOP•6d ago
I can customize them, but looks like the organization id always comes back as "default" even when I change between organizations 🤔
erquhart
erquhart•6d ago
hmm
Oscar Gallo
Oscar GalloOP•6d ago
Oh no, the organization change crashes the useQuery function 😂
erquhart
erquhart•6d ago
oh really? What are you seeing
Oscar Gallo
Oscar GalloOP•6d ago
[CONVEX Q(playground:getById)] [Request ID: d952ab936a354919] Server Error
Uncaught Error: Unauthenticated
[CONVEX Q(playground:getById)] [Request ID: d952ab936a354919] Server Error
Uncaught Error: Unauthenticated
Yeah, I'll leave that for the next release 😂 right now I'm doing a challenge to launch an AI product in only 9 days, and today is the last day 😂
erquhart
erquhart•6d ago
Good luck!
Oscar Gallo
Oscar GalloOP•6d ago
thanks 😄

Did you find this page helpful?