how can I hide a button in a page and let it visible only for admin?

thank you in advance for helping me out with this.

Just put a check in your pages onReady function so that when the page loads it checks the user viewing the page and if they are admin, then it shows the button.
https://www.wix.com/corvid/reference/wix-users.html
https://www.wix.com/corvid/reference/wix-users.html#currentUser
https://www.wix.com/corvid/reference/wix-users.User.html#getRoles

I want to thank you very much to open my eyes on the onReady function as I am still learning coding , it is working now with using the following code :

// hide addbook button
import wixUsers from ‘wix-users’ ;

$w.onReady( function () {

const currentUser = wixUsers.currentUser;
if (currentUser.role === ‘Admin’ ){
$w( ‘#addBookButton’ ).show();
}
else
{
$w( ‘#addBookButton’ ).hide();
}

})

now the only two problems:
1- I must reload the page so the button can appear after I login as admin.
2- this code only works for the owner not for admins.

Yes unless the user is already logged in when the page loads, the code will not run again when they log in later.

If you use a lightbox for your own Corvid login, then you can simply have the lightbox close after login and refresh the page that it was opened on.

However, if you are using the default Wix login, then you will have to look into using more code and the onLogin function.
https://www.wix.com/corvid/reference/wix-users.html#onLogin

As for the type of role, then note as stated in the Wix Users API that there are only three users with Wix.
https://www.wix.com/corvid/reference/wix-users.html

There are three types of users:

  • Visitor - A user who is not logged into your site.

  • Member - A user who is logged into your site.

  • Admin - The owner of the site.

If you want site contributors to have the same permissions, then you might be best suited given them a set role that you add to the allowed list.
https://support.wix.com/en/article/about-roles-permissions-contributors
https://support.wix.com/en/article/creating-member-roles-6943237

Thank you !
first problem is solved and working fine by refreshing the page after logging in :

// show addbook button for owner only
import wixUsers from ‘wix-users’ ;

$w.onReady( function () {

const currentUser = wixUsers.currentUser;
if (currentUser.role === ‘Admin’ && ‘Kellie’ ){
$w( ‘#addBookButton’ ).show();
}
else
{
$w( ‘#addBookButton’ ).hide();
}

})

// Refersh the page after successfull login
$w.onReady( function () {

wixUsers.onLogin( (user) => {

wixLocation.to(wixLocation.url);

} );
});

second problem I have to search more I think.
thank you again!

With your code here you shouldn’t need the additional onReady in the middle of your code with the refresh.

You can see an example of it without the second onReady line here in this other recent forum post.
https://www.wix.com/corvid/forum/community-discussion/download-button-help?

As for the user role you can see previous forum posts that will help with this like here.
https://www.wix.com/corvid/forum/community-discussion/get-the-information-of-user-roles
https://www.wix.com/corvid/forum/community-discussion/getroles-function-is-not-working/p-1/dl-5e148145dd7d620017498340
https://www.wix.com/corvid/forum/community-discussion/user-roles
https://www.wix.com/corvid/forum/community-discussion/urgent-send-a-user-to-location-based-on-member-role

Also, with your line here…
if (currentUser.role === ‘Admin’&&‘Kellie’){

You are using the && for a logical and, this might not work and you can look at using the or ’ ||’ instead which would be like this which is from a test example for radio group buttons…

if ($w('#radioGroup1').value === 'Paris' || $w('#radioGroup1').value === 'New York') {

So yours would be something like this…

 if (currentUser.role === 'Admin' || currentUser.role === 'Kellie') {

The previously linked previous post called User Roles gives you an example of using the && in your code.

    if (currentUser.loggedIn && currentUser.role === 'Admin'){

How to make a setting on the button on Wix when you click that button hidden button / another button will appear after that

Please always open your own posts instead of bumping up old ones.
You can link every other older post to your own if needed for better explanation or example.