currentUser.role not Admin?

I’m the owner on the site and the following works by showing the button and logs ‘Admin’ to the javascript console. However, another user who has the admin role on the site within wix logs in as ‘Member’. How do I make users ‘Admin’?

$w.onReady(function(){
const currentUser = wixUsers.currentUser;
if (currentUser.loggedIn && currentUser.role === ‘Admin’){
//Show components:
$w(‘#btnAdmin’).show();
}
console.log(currentUser.role);
});

Hi PJ. I’m using the exact same code, but I can’t even get the elements to show as the site owner. My console is reporting my user as a ‘Member’. What process did you use to login so that the user is identified as Admin? Also, do I need to add a members login to use this feature? (I don’t currently have one.)

I’m almost certian you would have to add the members feature. You should be able to add the feature, then hide those functions if it would never be customer-fronted stuff.

Hmm, I’ll give that a try. What is strange, though, is that Wix says that “when previewing your site, you are assigned the Admin role.” (See here .) But when I preview my site, the console reports that I am a Member (logged in = true).

PJ — Your suggestion worked. However, we seem to be having interrelated problems. After adding the members area, my console log still shows me (the site owner) logged in as a “Member”!

After reading their docs, the site owner is the only person that’ll show up as “Admin”, This actually compeltely defeats the purpose of the admin role for me. I’m moving the functionality into another adminTable DB that’ll be checked via a WixData call. It’s clunkyer, but I think it’s the only way to get it to work for me.

I don’t use the preview function much at all, always had issues. My sites are either non-launched, or I’m working on a new page I hide from public view until I’m ready to show it. So I’m always publishing the site and reviewing the live link.

Not sure if any of that helps you… :frowning: . Hope it does.

Well that’s a bummer. I also planned on allowing other “Admin” users special functionality on the live site. Since more than one contributor can have the Admin role, It defies logic to call the coding variable “Admin” if the other Admin users (besides the site owner) aren’t included under that label.

Furthermore, if only the site owner can be the admin (i.e., a single user), then it makes absolutely no sense to require the website to have a “Members Area” in order to show hidden elements by user — since the site owner is but a single user! And the site owner always remains the Admin, even when there is no members area. A major flaw in my opinion.

Yes… it’s dumb, I totally agree. That’s the thing I’ve noticed about Wix, some really really REALLY basic stuff they don’t seem to think about. Like, did you know you can’t delete a database collection? Nope, can’t do it, you have to delete the entire site and start over.

That’s just stupid, why? Who looked at that and said, “Oh great! Let’s launch without that!” They end up making some great stuff, but having to wade through miles of their development work on our production sites is extremely frustrating.

Lol. Good to know. Apparently you can’t delete “members only” pages either, as I just found out. You have to delete the entire Members Area app and start over. So watch out!