Show/hide Member menu item according to user role

Is there a way to hide or show a specific Members menu item by code? In this case, I have a menu item “Console” that appears in the Wix Members menu (the one that appears only for logged-in members), but I only want it visible (or selectable if that’s not possible) to the site Admin.

import wixUsers from 'wix-users';

$w.onReady(function(){
    const currentUser = wixUsers.currentUser;
    if (currentUser.loggedIn) {
       if (currentUser.role === "Admin") {
           //ADD CODE HERE TO SHOW ADMIN-ONLY MEMBERS MENU ITEM
        }
    }
});

WixUsers has been long deprecated, use WixMembers instead

import { currentMember}  from 'wix-member-frontend'
const userRoles = currentMember.getRoles() // Role[]
1 Like

If you are talking about the native member login menu bar, I don’t think you can manipulate it.

Why don’t you try adding the specific roles via the native page permission settings?

Or, you can use a dropdown element and code your own navigation menu according to the role.

1 Like

Yes, already have it set up so that the page is only accessible to specific user roles, but was hoping to also make it only appear in the Wix login menu for authorized users.

Looks like I’ll have to remove the page from the native menu and, as you suggest, add a custom dropdown menu or button :slight_smile:

1 Like