Multiple roles per user in Admin plugin

Hello, I'm trying to create an app using NextJS. I'm using Better-Auth with the admin plugin which seems good enough for what I need. However, I want to be able to provide users with different roles, but having multiple roles, e.g. Accounts, Sales etc. Using just the Admin plugin, how can I assign multiple roles to a user. I don't really want to use the organisation plugin, as I don't need that complexity just for multiple roles. Thanks!
1 Reply
Netrifier
Netrifier3w ago
You can pass multiple roles in the admin.createUser and admin.setRole functions by separating them with a comma.
const updatedUser = await authClient.admin.setRole({
userId: "user_id_here",
role: "admin,superadmin",
});
const updatedUser = await authClient.admin.setRole({
userId: "user_id_here",
role: "admin,superadmin",
});
But typescript will complain about this. I have a pr which adds support for passing multiple roles as an array with role inference
GitHub
feat(admin): Add support for passing multiple roles as array by Net...
Added ability to pass multiple roles as array to createUser and setRole in addition to single role as string Added InferAdminRolesFromOption type to provide roles type inference in functions Made r...

Did you find this page helpful?