J.D
2
//the imports....
function getRoleAndRedirect(){
return wixUsers.currentUser.getRoles()
.then(roles => {
if(roles.some(role => role.name === 'Staff')){
return wixLocation.to('/page-a');
}
if(roles.some(role => role.name === 'Client')){
return wixLocation.to('/page-b');
}
//if other roles or no role:
return wixLocation.to('/page-c');
})
}
function loginUser(){
wixUsers.propmptLogin()
.then(user => {
getRoleAndRedirect();
}).catch(loginUser)
}
}
$w.onReady(function () {
if (wixUsers.currentUser.loggedIn) {
//the hide-show as you wish +
getRoleAndRedirect();
} else {
//force log-in
loginUser();
})