how to extend clerk's users metadata
Im wondering how to extend clerk users model by adding some data about the user's role.
I know it can be done but I don't know how I can do it in a way to check once the user sign in it check if the user's email is in a table with a role and add it its correspondent role.
Clerk's docs has an example of adding metadata but the example is unclear for me
https://clerk.com/docs/users/user-metadata
6 Replies
To update a user with metadata from your backend , is just a call to updateUserMetadata and then pick the metadata you need
perfect, where will it be a good place to write that logic? can the sign up function of clerk have like a middleware
If you want it to happen after sign up just use the webhooks we fire one on creation.
Otherwise do something like
<SignUp>
redirect to page -> fires API endpoint to do inserts.
Ohhhh amazing, I will try to set up the webhook then! Thank you
is there a type for extending the next js req type for the clerk webhook events? In the docs there is one example where it import the type from the node sdk
The typing is the same but just "@clerk/nextjs/server" I believe.
oh true, for some reason I could auto import it. Thanks!