Hello,
I have encountered a similar issue before and you can adapt the scenario below:
You need to do the following to achieve the effect you are looking for:
- Create roles as instructed here: Creating Member Roles ;
- Add members to their respective roles as instructed here: Managing Your Member Roles
- Create a backend function to get the role of currently logged-in user:
import wixUsers from 'wix-users-backend';
export function getUserRoles() {
let user = wixUsers.currentUser;
return user.getRoles()
.then((roles) => {
if (roles.length > 0) {
return roles[0].name; // "Role Name"
} else {
console.log("Member has no roles");
}
})
.catch((error) => {
console.log("Backend Error: ", error);
});
}
- Import your backend function to get currently logged-in user role in frontend and use it in your front end code:
import { getUserRoles } from 'backend/userRoles'; //Assuming your function is getUserRoles and backend module is userRoles.jsw
$w.onReady(async function () {
let newRole = await getUserRoles();
//Add your code to use the role as you wish
});
- Add code to redirect your site visitor to the relevant page using wixLocation API.
This is just an approach I used and you should change it to suit your case.
Good luck!