What about just SHUT one function OFF ???
//-------------- USER-INTERFACE -----------------
let roles = [];
roles[0] = 'Staff';
roles[1] = 'Client';
//roles[2] = 'ADMIN';
//roles[3] = 'USER';
//roles[4] = 'SUPPORT';
//-------------- USER-INTERFACE -----------------
$w.onReady(function() {
let loggedIn = wixUsers.currentUser.loggedIn
if (loggedIn) {getRoleAndRedirect();}
else {loginUser();} //--> force log-in
});
//the imports....
function getRoleAndRedirect(){
return wixUsers.currentUser
.getRoles()
.then(roles => {
if(roles.some(role => role.name === roles[0])){
return wixLocation.to('/page-a');
}
if(roles.some(role => role.name === roles[1])){
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)=>{});
}
BTW, it’s the same code written by J.D. (but a little bit modified).