whoamiW
Convex Community3y ago
2 replies
whoami

Receiving JWT fields beyond what UserIdentity provides

Hi team, we tried to implement RLS with clerk provided auth fields, I wanted to know is there any plans extending
auth.getUserIdentity()
to receive fields other than what
UserIdentity
provides? Passing
org_id
to
gender
field sounds like a hack but I suppose there should be a better way?

export const { withQueryRLS, withMutationRLS } = RowLevelSecurity<
  { auth: Auth; db: DatabaseReader },
  DataModel
>({
  chats: {
    read: async ({ auth }, chat) => {
      const identity = await auth.getUserIdentity()
      if (!identity) {
        throw new Error('Unauthenticated call to mutation')
      }
      const { gender: org } = identity
      return chat.org === org
    },
    modify: async ({ auth }, chat) => {
      const identity = await auth.getUserIdentity()
      if (!identity) {
        throw new Error('Unauthenticated call to mutation')
      }
      const { gender: org } = identity
      return chat.org === org
    },
  },
})


Also we've found that when passing whatever clerk values to
address
fields like

address: {{org.id}}
the auth will crash, not sure if there is any bug associated with clerk or convex.
Was this page helpful?