Show Elements to Admin only

Is there a way we can show elements to an admin account only so they can however over the element and edit but if not logged in as admin it won’t show…?

Yes, you can. You would need to Hide the buttons in design mode, get the Role of the current user on the page and if it is Admin, you .show() the buttons. Look here: Page Not Found - Velo API Reference - Wix.com

I am still confused on how to achieve this, can you help me?

Hi Robert,
Set the elements to be ‘Hidden on load’ (using properties panel).
Here’s a skeleton for a code:

import wixUsers from 'wix-users';
$w.onReady(function(){
    const currentUser = wixUsers.currentUser;
    if (currentUser.loggedIn && currentUser.role === 'Admin'){
        //Show components:
        $w('#button1').show();
    };
});

Liran.

2 Likes

Liran, slightly OT, but is that .loggedIn necessary? If you are not logged in, you give users Visitor status. Or, under which circumstance does Wix return Admin as user when he is not logged in?

Hello Giri,

Yes, if a visitor is not yet logged in he must be of type visitor. In the above example checking currentUser.loggedIn is not required.

Thanks so much Liran, really really appreciate it. :slight_smile:

Hello. I used Liran’s code exactly and it’s not working for me. If I change the parameter to show the elements for “Visitor” then the elements show, but not for “Admin”. Thanks in advance!

Can i use this also for an object that i do not want to shown for no-members of my site?

Please add your own issue into a new post instead of bumping up an old post. Explain what you are trying to do, what works, and what doesn’t. Also, add any code in a code block as stated in the Forum Guidelines.

This post is an old post and is being closed.