clerk how to implement user roles
What is the best way to implement user roles (let’s say admin and user) and authorization based on them (to keep it simple let’s say admin can change anyone’s role while user can’t change anything)?
5 Replies
it Depends.
Organizations is built for this, but aimed at B2B and has admin and member where admin can change the roll, add, delete members.
Otherwise public metadata can store the roles and then you can access the metadata anywhere you need
using organization means you have to pay more, just create a one-to-one table called
profile
to put type-safe role column using enum..
if u dont mind type, just use the metadataAnd i use getauth() to access it?
Can you give some idea ok how to create the profile on user login if the user doesn’t have one because I made one that parent component that check it and if doesn’t have one it redirects to a profile creator but when I push the router after mutation it doesn’t refresh the previous query to check if doesn’t have one
You can use middleware to redirect user to profile creation page