How do you hide a button when a Member plan expired

Am I missing something here, when I load the page when the plan is expired it does hide the button but when the condition is false it shows al the button instead of two as I want?
let user = wixUsers.currentUser;
let currentDate = new Date();
wixUsers.currentUser.getRoles()
.then((roles) => {
let firstRole = roles[0];
let roleName = firstRole.name;
console.log(roles[0])
user.getPricingPlans()
.then((pricingPlans) => {
let firstPlan = pricingPlans[0];
let expiryDate = firstPlan.expiryDate;
console.log(pricingPlans[0]);
if (roleName === ‘Staff’) {
$w(‘#buttonStaff’).show();
$w(‘#buttonmaj’).show();
$w(‘#ButtonE’).hide();
$w(‘#button1’).hide();
$w(‘#button3’).hide();
} else {
if (roleName === ‘Staff1’) {
$w(‘#button3’).show();
$w(‘#buttonStaff’).hide();
$w(‘#buttonmaj’).hide();
$w(‘#ButtonE’).hide();
$w(‘#button1’).hide();
} else {
if (currentDate < expiryDate) {
$w(‘#button3’).hide();
$w(‘#buttonProf’).hide();
$w(‘#buttonmaj’).hide();
$w(‘#ButtonEleve’).show();
$w(‘#button1’).show();
} else {
$w(‘#button3’).hide();
$w(‘#buttonProf’).hide();
$w(‘#buttonmaj’).hide();
$w(‘#ButtonEleve’).show();
$w(‘#button1’).hide()
}
}
}
});
});
});

I have checked your code. Please note that when the plan has expired, the value here:

let firstPlan = pricingPlans[0];

becomes undefined as it returns only active plans. Therefore, you can’t compare the current date and expiration date, as the last one is undefined.

In this case, I’d recommend simply checking if the user has a valid plan or not.
You need to remove the following line:

 let expiryDate = firstPlan.expiryDate; 

And change

  if (currentDate < expiryDate) to if (firstPlan !== undefined)

If you have any questions, feel free to get back to us!