Hide Button with Roles

Hello, I am new so please take it easy :).

I searched through the forum and found a code that seemed to be exactly what I needed. In my case, if a user has the role of “SiteAdmin” then show “Button161”. It simply does not seem to work though. Users sign in do not have the role of “SiteAdmin” and can still see the button. Any help would be greatly appreciated:

});
import wixUsers from ‘wix-users’ ;

$w . onReady ( function () {

const currentUser = wixUsers . currentUser ;

if ( currentUser . role === ‘SiteAdmin’ ){
$w ( ‘#button161’ ). show ();
} else {
$w ( ‘#button161’ ). hide ();
}
});
});

Not really recommended to use old APIs, but well it should work like this.

import wixUsers from'wix-users';

$w.onReady(function () {
    const currentUser = wixUsers.currentUser;
    console.log("Current-User: ", currentUser);

    if (currentUser.role === 'SiteAdmin'){ 
       $w('#button161').show();
    } 
    else {
       $w('#button161').hide();
    }   
});

Take a look onto CONSOLE in PREVIEW-MODE, what do you get as OUTPUT ?

Just a reference to an old collection I deleted but I dont think its related, otherwise there is nothing:

"Running the code for the Intranet page. To debug this code in your browser’s dev tools, open sw891.js.

ServerValidationError: Initial data fetching failed for one of the datasets Caused by Error: WDE0026: The IntranetLoanProgramLanding collection was removed, so you cannot work with it. To restore its data, create a new collection with the same name.

Caused by: Error: WDE0026: The IntranetLoanProgramLanding collection was removed, so you cannot work with it. To restore its data, create a new collection with the same name."

Its almost like it doesnt even see the code there for some reason. I have my role named “SiteAdmin”. Thank you for taking a look.

Did you copy and paste my proposed CODE ?

Do you have more code on your site?

  1. DEACTIVATE ALL YOUR OTHER CODE FIRST !!! (best = blank code-page)
  2. COPY & PASTE MY PROPOSED-CODE ONTO YOUR PAGE.
  3. PUBLISH YOUR WEBSITE.
  4. OPEN YOUR BROWSER (CHROME) and PRESS F-12 → CONSOLE.
  5. TAKE A LOOK ONTO RESULTS.

By the way…

  1. Did you install the Wix-Members-APP ?
  2. You can find - - > PrivateMembersData/PublicMembersData inside of your DATABASE?
  3. And you seem to have a PROBLEM with one of your used DATASETS (DATASET-CONNECTION).