Casbin Forum runs on Casnode, the open-source Discourse-style forum. Try the Casnode demo →
Casbin Forum

Hi everyone. I want assign user role. Either at sign up time or by appending user to the existing roles list, instead of fetching all users list, adding user to the list and passing entire list to the api.
Is it possible to append user in roles list ?

Any help would be appreciated

3views
2users
1 minread

Why don't you just ask AI

Of course it's possible to give a role to a user

users shouldn't "be in" the roles list, the list of roles is for roles

users should HAVE roles but users AREN'T roles themselves

giving a user a role looks like this in the database usually

g, [userUUID], role

So to give a user a role, you just simply create a rule in the database via casbin that says "g, [userUUID], role"

You don't "add a user to the list of roles"

Thank you for your efforts.
I simply want to assign role to the user. I also took help of AI. What i got to know is that i would be required to first fetch list of all users with that role, the append this user to that list, and call the api. So got this flow for assigning role to the user.
Correct if i am wrong.

That's incorrect. AI is wrong

casbin checks if a user has a role by looking in the database for a g, [userUUID], [role] rule

g means grouping I think

For example you want to check if a user has the role "admin":
userUUID = 1234 (just for example)

casbin looks in database for a rule like
g, 1234, admin

So to GIVE a user a role, you just simply need to add a rule to the database via casbin like "g, 1234, admin"

There is no list of roles involved in giving a user a role

For example in Go (language) it would look like this:

enforcer.AddRoleForUser("1234", "admin")

It's probably very similar in whatever language you're using

Ask AI:

How to give user a role in Casbin in [programming language you're using]:
enforcer.AddRoleForUser("1234", "admin")

1 / 7
Nov 2025