Harmony
Harmony4w ago

Integrating convex with clerk

Hi all, I have been able to setup clerk with convex but I was wondering how can I include the private_metadata field of users in the ctx.auth object :dankSpin:
3 Replies
Convex Bot
Convex Bot4w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
Harmony
HarmonyOP4w ago
In the JWT template i set the claims to
{
"aud": "convex",
"name": "{{user.full_name}}",
"email": "{{user.primary_email_address}}",
"picture": "{{user.image_url}}",
"nickname": "{{user.username}}",
"given_name": "{{user.first_name}}",
"updated_at": "{{user.updated_at}}",
"family_name": "{{user.last_name}}",
"system_role": "{{user.private_metadata.system_role}}",<- I cannot get the
"phone_number": "{{user.primary_phone_number}}",
"clerk_user_id": "{{user.id}}",
"organizations": "{{user.organization_memberships}}",
"email_verified": "{{user.email_verified}}",
"phone_number_verified": "{{user.phone_number_verified}}"
}
{
"aud": "convex",
"name": "{{user.full_name}}",
"email": "{{user.primary_email_address}}",
"picture": "{{user.image_url}}",
"nickname": "{{user.username}}",
"given_name": "{{user.first_name}}",
"updated_at": "{{user.updated_at}}",
"family_name": "{{user.last_name}}",
"system_role": "{{user.private_metadata.system_role}}",<- I cannot get the
"phone_number": "{{user.primary_phone_number}}",
"clerk_user_id": "{{user.id}}",
"organizations": "{{user.organization_memberships}}",
"email_verified": "{{user.email_verified}}",
"phone_number_verified": "{{user.phone_number_verified}}"
}
Then I have something like this to get the user identity
export async function getCurrentUser(auth: Auth): Promise<ConvexUserIdentity | null> {
const identity = await auth.getUserIdentity();
if (!identity) {
return null;
}

return {
tokenIdentifier: identity.tokenIdentifier,
subject: identity.subject,
email: identity.email as string | undefined,
name: identity.name as string | undefined,
nickname: identity.nickname as string | undefined,
picture: identity.picture as string | undefined,
emailVerified: identity.emailVerified as boolean | undefined,
system_role: identity.system_role as SystemRole | undefined,
organizations: identity.organizations as string[] | undefined,
};
}
export async function getCurrentUser(auth: Auth): Promise<ConvexUserIdentity | null> {
const identity = await auth.getUserIdentity();
if (!identity) {
return null;
}

return {
tokenIdentifier: identity.tokenIdentifier,
subject: identity.subject,
email: identity.email as string | undefined,
name: identity.name as string | undefined,
nickname: identity.nickname as string | undefined,
picture: identity.picture as string | undefined,
emailVerified: identity.emailVerified as boolean | undefined,
system_role: identity.system_role as SystemRole | undefined,
organizations: identity.organizations as string[] | undefined,
};
}
:1_nymphelia_Sip: Although I cannot get the system role thingy to pickup my user system_role :Erm: Ahh i dont think clerk allows private metadata through a JWT template
Danny
Danny4w ago
You'd be better off fetching the user from clerk when needed

Did you find this page helpful?