Autorefresh for show the button

I have this code for if you are a member you can see this button, but i need to refresh the page for see the button when you log in each time

import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;
import wixLocation from ‘wix-location’ ;

$w.onReady( function (){
const currentUser = wixUsers.currentUser;
if (currentUser.loggedIn && currentUser.role === ‘Member’ ){
//Show components:
$w( “#button13” ).show();

} 

});

You have to run it on login:

//import etc...
let user = wixUsers.currentUser;
function showButton(){
   if(user.role === "Member"){
$w("#button13").show();
}
}
$w.onReady() => {
showButton();
wixUsers.onLogin(u => {
user = u;
showButton();
})

Ohh ok I will try it . By the way, are there one option for roles creates by me? Not admin, member or visitor.

I’m not sure I got what you were asking

I mean for example show button only for a Role( but not admin, visitor or member role) a custom role that I created

import wixUsers from 'wix-users';
// ...
let user = wixUsers.currentUser;
const irrelevantRoles = ["Admin", "Member", "Visitor"];
user.getRoles()
.then(roles => {
const roleNames = roles.map(e => e.name); 
const relevantUserRoles = roleNames.filter(e => !irrelevantRoles.includes(e));
if(relevantUserRoles.length > 0){$w("#button13").show();}
})

Ohh ok thanks. So( const roleNames = roles.map(e => e.name); ) here in name is where I have to put the name of role, right?

@aapgcup No. Just use the code above as is. No need to change anything.

Thanks so much

I will add comments:

import wixUsers from 'wix-users';
// ...
let user = wixUsers.currentUser;
//declare which role is not interesting:
const irrelevantRoles = ["Admin", "Member", "Visitor"];
//get the roles
user.getRoles()
.then(roles => {
//extract the name property of the role:
const roleNames = roles.map(e => e.name); 
//filter out the irrelevant role names:
const relevantUserRoles = roleNames.filter(e => !irrelevantRoles.includes(e));
//if there's any role left (meaning -- there's a relevant role) show the button: 
if(relevantUserRoles.length > 0){$w("#button13").show();}
})

This told me it has an error in $w.onReady() => { to down

/import etc...
let user = wixUsers.currentUser;
function showButton(){
   if(user.role === "Member"){
$w("#button13").show();
}
}
$w.onReady() => {
showButton();
wixUsers.onLogin(u => {
user = u;
showButton();
})