Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: A dynamic user roles value, multiple user roles (array) or single value user role. #598

Open
latuconsinafr opened this issue Feb 7, 2023 · 1 comment

Comments

@latuconsinafr
Copy link

Hello, first of all, it is an excellent library and also helps a lot. But, can we make the roles property to be dynamic? I mean it could take either an array of an enum or a single value enum. Cause I encountered an error when I tried to supply a single value enum to the roles property.

Then, I took a look at this line of code:

user.roles?.forEach((role) => {

The forEach will cause the error when roles are supplied by a single value enum. Instead we could do something like this:

if (Array.isArray()) {
  user.roles?.forEach((role) => {
    ability.permissionsFor(role);
  });
} else {
  ability.permissionsFor(user.roles);
}

Thanks.

@belgamo
Copy link
Contributor

belgamo commented Oct 3, 2023

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants