currentUser.getRoles not returning user roles

Hi Wix Forum!

I want to automatically get my users to their special member page (in a router page), based on their current role.

Most works just fine, just that I do not have any clue why the call to getRoles on current user executes the error handler although I am making near plain vanilla calls. Any help more than super welcome ;).


My code:

import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
import wixWindow from ‘wix-window’;

$w.onReady( function () {
//TODO: write your page related code here…
if (wixWindow.rendering.renderCycle === 1) {
const user = wixUsers.currentUser;
user.getRoles()
.then(roles => {
console.log(“ROLES: “+JSON.stringify(roles));
if (roles.length===1){
if (roles[0].name===“Company”) return wixLocation.to(”/company/dashboard”)
if (roles[0].name===“Student”) return wixLocation.to(“/student/dashboard”)
if (roles[0].name===“Staff”) return wixLocation.to(“/staff/dashboard”)
} else {
console.log(“roles.length !== 1”);
}
}, err => {
console.log(“user.getRoles ERROR”); // yep I see you
console.log(JSON.stringify(err)); // I get an empty object: {}
})
}
});

1 Like

This function only works on a live site, not in preview mode. Not clear from your post which environment you are using to test.

Hi @davebogan98 , you are right. I ran it from the live site.

I can’t access User Roles either.

Is it because of the change in where they put it on the dashboard of each individual site??

They recently changed the way the site dashboard is setup and changed the wording and placement around for different things inside of Customer Management…

OMG, never saw that coming… I am surprised they would put it in production without regression testing or if there is breaking change without giving prior notice. Where did you get that information?

@martin86078 To be honest, I am on wix platform like 24/7 and notice a whole bunch of changes that goes on inside the system so that is why I could highlight the change. I wish they could send out emails to people about the change or at least notify us that they are in the progress of changing the structure and look.

I guess we will just have to wait for someone from wix to reply or at least notify us on this thread.

Few people like @yisrael-wix , @brett-haralson , @alexander-wix , and @amit-wix , to name a few, who could help send this up to Wix. Hopefully they will see this notification, fingers crossed.

If just tested my code in the live site, and userRoles works just fine.

Of course…now it works. Just checked it with my site. Glad they could fix that bug.

Haha, it changed again :joy:

I agree, a little heads up before breaking changes would be great, even if wixCode is still in beta. hehehe