Hi,
I have checked you code and I see a number of issues.
Please see a working code example below:
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
$w.onReady(function () {})
export function button9_click(event) {
const user = wixUsers.currentUser;
user.getRoles()
.then((roles) => {
switch (roles[0].name) {
case 'Admin': //name of the role
wixLocation.to("https://microsoft.com");
break;
case 'test': //name of another role;
wixLocation.to("https://microsoft.com");
break;
default:
wixLocation.to("https://microsoft.com");
}
})
}
To get the current user you need to use the wixUser.currentUser;
Names of the roles are case sensitive, so should be exactly like in dashboard (e.g. Admin);
The code works only on the live site, therefore you won’t be redirected in the editor;
Please note that roles[0] gets only the role that appeared first for the user. If you wish to check all the users’ roles you need to use a different syntax. Click here to learn more about the getRoles() function.
This topic is pretty old. To help keep the forum organised, please open a new topic outlining what you’re facing, what you’re hoping to achieve and what you’ve already tried.