Divert based on User

The use case I’m trying to solve is to redirect users trying to navigate to a given page based on their user email (or user id)

So logged in member requests page A

I want to be able to redirect some users (<6 so not a hard coding issue) based on their email or user ID to page B instead

As someone new to javascript, how would be the best way to go about this? Any help much appreciated

When you say <6 so not a hard coding issue. Do you mean it’s not an issue to hard-code the soulution, or that it’s not an issue if it’s hard coded?

If you don’t want it hard coded, then giving them a role, then checking for that role sounds like the easiest solution (Might even be easier than hard-coding it)

Thanks very much Simen - I don’t know why I didn’t consider roles. I’m new to javascript so learning the nicities of js and Velo probably stopped me thinking more broadly. I’ll take a look at the examples for something in this space using roles and hopefully that would be a much more elegant solution. Thanks again.

@rjbwilts No problem, it’s also about learning to work with the platform and what tools it provide, such as roles. I’d guess the easiest way would be with a button that you use a onclick function on (triggered when clicked). Something like this (In this example I’ll call the button #redirectButton)

import { currentMember } from 'wix-members';
import wixLocation from 'wix-location';

$w.onReady(function () {


$w('#redirectButton').onClick(()=>{
    let B = "admin" //looking for the role called admin
    currentMember.getRoles()
  .then((roles) => {
    for(let i = 0; i < roles.length; i++){  //Runs trough all the roles of the user
        if(roles[i].title == B){ //if they have the role B, send them to /pageB
            wixLocation.to("/pageB")
        }
    }
    wixLocation.to("/pageA")  //If there are no matches, send them to pageA
  })
  .catch((error) => {
    console.error(error);
  });
})
})