Hi Community,
I am new here and this is my first post. I don’t know how to code but I’m good at find solutions, copy-pasting
I’ve recently created an e-learning site which works fine. After login, there is a page which redirects user to respective page based on their role. Redirection works fine but apparently it has become very slow. It takes about 25-45 seconds for the redirection, and on mobile site it is worst. I had found below working code (thanks to the contributor) which is on the page.
I have about 500 users at this point. Need your help in solving this slowness…
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===“Junior KG”) return wixLocation.to(”/juniorkg”);
if (roles[0].name==="Senior KG") return wixLocation.to("/seniorkg");
if (roles[0].name==="Nursery") return wixLocation.to("/nursery");
if (roles[0].name==="Playgroup") return wixLocation.to("/playgroup");
if (roles[0].name==="Admin") return wixLocation.to("/playgroup");
}else{
console.log("roles.length !== 1");
wixLocation.to("/signin");
}
}, err => {
console.log("user.getRoles ERROR");
console.log(JSON.stringify(err));
});
}
});