Hello!
I am working with the wix-users module and the roles, and I think there’s a bug when trying to get the role(s) of a user.
When I use user.getRoles() , I get an empty list; whereas the user.role current value is “Member” (as expected).
Then, since the documentation (https://www.wix.com/code/reference/wix-users.User.html#role) states that user.role is deprecated in favor of user.getRoles() , I think that the list returned by getRoles() should have the “Member” role included in it (same as user.role), because at this moment the only way to get that role is by the use of user.role , which is deprecated !
I would appreciate if someone can confirm whether this is a generalized behavior, or explain why this could be the expected result.
Thanks!
EDIT:
Tested on the published site.
#wix_users #role #roles #members #getroles #bug
1 Like
It’s not clear from your post whether you tested it in preview mode or on your published site. getRoles() works only on the published site.
Another option to consider is whether you resolved the promise that getRoles() returns as it’s an asynchronous method.
It was on the published site and checked in the then of the promise return. I’ll write it up for QA.
Were you able to reproduce it from scratch?
Please share the problematic code
Hi again,
Please make sure you set Roles to your site members, as explained here: Site Members: Creating Member Roles | Help Center | Wix.com
If no role is set, you would get an empty array, so it seems that the result you’re getting is in fact expected and not a bug.
Thanks for the clarifications, Steve.
What I understand is that there are two different types of roles:
(a) the Wix “default” roles being those listed by Steve (Member, Admin, Visitor), and
(b) those created by the Admin in the dashboard website as the documentation link shared by Ohad.
Then, since the user.role is deprecated, I was expecting to receive all roles in the user.getRoles() returned list, and use that to check the “default” wix role when logged in (Admin or Member) independently of the role assigned through the dashboard.
@gasparmelsion The current work around is to treat a getRoles() failure (catch) as a ”Visitor”. An empty array as “Member” and you will get a role in the array as name=“Admin” For Admin. Try adapting the code with this model.
cheers
Steve
Thanks @stevendc , I will try what you suggest.
Just one question: is this a preliminary update from the Wix code, or is the way it is being working also before finding the “bug”?
@gasparmelsion For now take this as the model. I have raised the issue internally and it is being assessed.
As discussed the wix-users API has evolved after much of your site was designed. There are many more features available now that we’re not then where code was used as a work around. So the authentication model may need to be reviewed.
For example each page can be limited to specific member role based access in the Editor. This wasn’t available for you original site design so many pages are checked in code instead of using the site member capabilities.
Hope that answers the question.
Cheers