(REQUEST) Single Button - URL Redirect Per Role ID

Hi,

Could someone please help me in terms of coding something for the following statement;

Button - ‘MyRecipes’
Expected Outcome - Based on ‘Role ID’ on click direct user to ‘URL’ / ‘Page’
Note: There would be a multitude of Roles to check.

I understand that each role does have a unique ‘Role ID’


What would be the ideal code I’d need to use in CORVID mode to have this button behave as stated above.

TIA :slight_smile:

import wixUsers from 'wix-users';

$w.onReady(function () {
    load_UserData()
 
    $w('#MyRecipes').onClick(()=>{
      // here your own code
      // if-else and let's go
      //.....do something....
    })
})

function load_UserData (parameter) {
 let user = wixUsers.currentUser;
 let userId = user.id;           // "r5cme-6fem-485j-djre-4844c49"
 let isLoggedIn = user.loggedIn; // true

    console.log(user)
    console.log(userId)
    console.log(isLoggedIn)
 
    user.getEmail()
    .then( (email) => {
 let userEmail = email;      // "user@something.com"
    } );

    user.getRoles()
    .then( (roles) => {
 if(roles.length > 0) {
 let firstRole = roles[0];
 let roleName = firstRole.name;                // "Role Name"
 let roleDescription = firstRole.description;  // "Role Description"

            console.log(firstRole)
            console.log(roleName)
            console.log(roleDescription)
        }
 else {
            console.log("Member has no roles");
        }
    });
   let userRole = user.role
   console.log(userRole)
}

Take a look onto your CONSOLE. (Code is not tested, just brainstorming) :grin:

Thanks,

So when looking on console, it does find the role / description etc.
If this code determines role (Example - " Purely Peach #1 ")

In terms of the ‘Role’ determining the URL/ On-Click function what would I put in this blank section;
import wixUsers from ‘wix-users’ ;

$w . onReady ( function () {
load_UserData ()

$w ( '#MyRecipes' ). onClick (() => { 
  // here your own code 
  // if-else and let's go 
  //.....do something.... 
 }) 

})