Having some issues on website that I need to solve.
1.) The pages that are member only pages should not be showing up on the navigation menu for any guest browsing my site. But in our site member pages are being displayed without anyone being logged in. How can page titles and sub-page titles in the navigation bar be connected to the permissions of member so that they are only shown if the member is logged in.
2.) If this cant be done how can I add something that can make the pages I want accessible to only certain roles appear when user logs in?
Note: at this time there are 5 different roles.
-
Guest user or member that has signed up but has not be assigned a role. (should not be able to have access to any special pages. This role is probably set up by default wix and does not need anything.)
-
Level 1 user has been assigned a level 1 role. (can access whole site plus pages that are site member pages assigned to this role.)
-
Level 2 user has been assigned a level 2 role. (can access whole site plus pages that are site member pages assigned to this role.)
-
Level 3 user has been assigned a level 2 role. (can access whole site plus pages that are site member pages assigned to this role.)
-
Admin user has been assigned a Admin role. (can access whole site plus all site pages that are site member pages. This role is probably set up by default wix and does not need anything)
You will need to setup all of the above menu settings and role options in the Wix Crm first.
Then after that you have the option of adding code to your website so that you can get the current users role either when they login or for a certain user role only event or to take a specific user role to one page or another for example.
https://www.wix.com/corvid/reference/wix-users.User.html
Thanks for the information
I have completed all the steps you mentioned on the the top of your post. (Creating member roles, member only pages and have hidden the pages.)
I am now at what I believe would be the code witting stage. I am a beginner in code writing but reading the link provided I believe I would have to start it of with:
import wixUsers from 'wix-users';
// ...
let user = wixUsers.currentUser;
let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
user.getRoles()
.then( (roles) => {
let firstRole = roles[0];
let roleName = firstRole.name; // "Role Name"
let roleDescription = firstRole.description; // "Role Description"
} );
To my understanding this code pulls the current logged in users role. So then I would need to have the code read if the current member role is level 1 then user should have certain pages shown to them. (What would be the best way to do this? a dropdown that populates the pages they can see and when they select the option in drop down it takes them to that page?)
I have written some code but having some issues with it. It displays current user email and role name in a two separate boxes. But it doesn’t display on page the proper button and text field with the associated role name that is being displayed on page. Can someone help me with what could be wrong in this code.
import wixUsers from ‘wix-users’;
$w.onReady( function (){
const currentUser = wixUsers.currentUser;
currentUser.getEmail()
.then( (email) => {
let userEmail = email; // “user@something.com”
$w(‘#input1’).value = userEmail; // “Displays user email on page”
} );
currentUser.getRoles()
.then( (roles) => {
let firstRole = roles[0];
let roleName = firstRole.name; // “Role Name”
let roleDescription = firstRole.description; // “Role Description”
$w(‘#input2’).value = roleName; // “Displays user role on page”
} );
if (currentUser.roleName === ‘Instructor’ && currentUser.loggedIn){
//Show components:
$w(‘#button1’).show();
$w(‘#text76’).show();
}
else {
//Hide components:
$w(‘#button1’).hide();
$w(‘#text76’).hide();
}
if (currentUser.roleName === ‘Master Instructor’ && currentUser.loggedIn){
//Show components:
$w(‘#button51’).show();
$w(‘#text77’).show();
}
else {
//Hide components:
$w(‘#button51’).hide();
$w(‘#text77’).hide();
}
if (currentUser.roleName === ‘Corporate’ && currentUser.loggedIn){
//Show components:
$w(‘#button52’).show();
$w(‘#text78’).show();
}
else {
//Hide components:
$w(‘#button52’).hide();
$w(‘#text78’).hide();
}
});