Is there a way to make a button visible only to certain users using badges as permissions?

This code I used from This Post is the current code I am using which works fine for only showing a button to Admin ranking members, however, I do not want to make everyone that I want to use this button an Admin or some variant of a special rank. Is there a way that I can use badges assigned to users to accomplish this, maybe some “if user has this badge” function that I am unaware of?

// show delete button for admin only
import wixUsers from ‘wix-users’ ;

$w.onReady( function () {

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

})

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

wixUsers.onLogin( (user) => {

wixLocation.to(wixLocation.url);

} );
});

Any and all help is greatly appreciated, thank you much!

This can be better managed with Roles, you have it right in the first instance, but can vary roles, for example:

import wixUsers from'wix-users';

$w.onReady(function () {
const currentUser = wixUsers.currentUser;
if (currentUser.role === 'Admin' || currentUser.role === 'Another Role' || currentUser.role === 'A Third Role'){ 
       $w('#deleteContentSelected').show();
} else {
       $w('#deleteContentSelected').hide();
       }
})

Can also be done with badges, but it requires passing ID’s to backend code

I was not aware that you did not have to stick to the default role. Thank you much for the explanation

I’m trying this with a custom-created role, but it’s not working because when a member who has this custom role is logged in, their role is returned as “Member” rather than the role’s name that I set. Does this not work with custom roles?

Has someone resolved this issue that Eric identified?

@support-3
Everything works. You can do your role-testings here…

https://russian-dima.wixsite.com/login-system

How to SETUP a ROLE?

https://russian-dima.wixsite.com/login-system/info

Register a new role then register a new user by your own choosing a ROLE.
Login to the Login-System and take a look onto what you get. :wink:
Everything is possible!

@zackarydent Don’t forget to do this in backend if necessary because you are playing with roles and you don’t want to let any user see the admin button.