Role based page redirection is slow

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 :stuck_out_tongue_closed_eyes:
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));   
            }); 

}

});

1 Like

Community experts, anyone here to help?

Ive got the same problem, but maybe its just the way wix works? When i wanted to follow this post, i had to login ofcourse, and the login-process was slow here as well … At least here there was a sort of a login-loading function, as the “login” button turns grey. You sort of know that its loading, and that the waiting time isnt an error. The member page login needs something like this i think.