Hi there! I was not referring to the visitor, member, or admin permission. I am referring to the custom roles for our members where we can set their page access. I created two new roles, “Client” and “Freelancer”. Is there any way I can get the currentUser’s role or is it not possible for now? Lastly, What is the [groups] for in the PrivateMembersData dataset? Thank you.
You can get the site members user role simply by using the WIX Users API
https://www.wix.com/corvid/reference/wix-users.html
https://www.wix.com/corvid/reference/wix-users.User.html#getRoles
Once you have setup member roles within your site, these roles will also be available to be used in the getUserRole function as well as just the three defaults from Wix.
If you search the forum, this has been asked many times before.
https://www.wix.com/corvid/forum/community-discussion/get-the-information-of-user-roles
https://www.wix.com/corvid/forum/community-discussion/getroles-function-is-not-working/p-1/dl-5e148145dd7d620017498340
https://www.wix.com/corvid/forum/community-discussion/user-roles
https://www.wix.com/corvid/forum/community-discussion/urgent-send-a-user-to-location-based-on-member-role
Finally, just note that as stated in the API info, that Wix Users API will only work fully in a live published site, so if you test it in preview mode then certain parts of it won’t work.
The APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality.
The APIs in wix-users can only be used once the page has loaded. Therefore, you must use them in code that is contained in or is called from the onReady() event handler or any element event handler.
Hello,
I am trying to get roles like so with promise
But I got no result it never go in to the promise.
import wixUsers from ‘wix-users’ ;
// …
let user = wixUsers . currentUser ;
user . getRoles ()
. then ( ( roles ) => {
let firstRole = roles [ 0 ];
let roleName = firstRole . name ; // “Role Name”
let roleDescription = firstRole . description ; // “Role Description”
} )
I can console.log(“user”), but I am the owner why role is “Member”…
id: “ftEe77188-e8b4-4de7-b025-test”
loggedIn: true
role: “Member”
Good luck with getting an answer - I have same problem. I think it’s because I enabled a plan for myself during testing…
Why console.log(‘user’) and not console.log(‘roleName’)?