RJ
RJ2y ago

Some Convex Clerk authentication questions

1. In the "Calling storeUser from React" section of the "Storing Users in the Convex Database" page (https://docs.convex.dev/auth/database-auth#calling-storeuser-from-react), what is the userId useState used for? Removing it entirely seems to work just fine. 2. I'm observing that the storeUser mutation located here (https://docs.convex.dev/auth/database-auth#storeuser-mutation) is not causing the name field to be set for the two accounts that I've tested this with. I'm not familiar at all with what's going on under the hood with this auth stuff, but is it possible that this is a Convex bug?
3 Replies
Michal Srb
Michal Srb2y ago
1. userId in React state could be useful if you want to thread the userId through the client code (pass it to another server call or some other client state). Alternatively you can always refetch the userId from the auth token in any Convex query/mutation that needs it. Our demo uses the latter approach here: https://github.com/get-convex/convex-demos/blob/main/users-and-auth/convex/sendMessage.js
GitHub
convex-demos/sendMessage.js at main · get-convex/convex-demos
Demo apps built on Convex. Contribute to get-convex/convex-demos development by creating an account on GitHub.
Michal Srb
Michal Srb2y ago
2. The example on that page uses the identity.name field. If you're using Clerk your JWT token probably doesn't include a name field. You need to change it use one of the fields that are present. We're working with Clerk to add "fullName" to the list of available shortcodes you can add in your JWT token template.
RJ
RJOP2y ago
Just to be clear, though, it's not serving any purpose in specifically that example code? That in particular is the source of my confusion. I see! My Clerk JWT token includes fields for givenName and familyName, so I suppose I need to modify that example to use those. Thanks!

Did you find this page helpful?