Hi,
I would like to make an edit button visible only to the owner of the listing.
I am not a coder and have no idea how to code it, this is why I hope someone can help me out in this. Thanks a lot!
The properties of the image is ‘hidden on load’.
My current code is after the import wixUsers:
$w.onReady( () => {
let user = wixUsers.currentUser;
let userId = user.id; // “r5cme-6fem-485j-djre-4844c49”
let isLoggedIn = user.loggedIn; // true
if (wixUsers.currentUser.Owner) { // This should refer to the “_owner” field in the database
$w(“#image10”).show();
}
});
You can check the roles and see if the current user is admin
Or you can hard code the userId which i don’t recommend
import wixUsers from 'wix-users';
const user = wixUsers.currentUser;
$w.onReady(()=>{
user.getRoles()
.then( (roles) => {
const isAdmin = roles.some(el=>el.name==="Admin")
console.log({isAdmin})
if( isAdmin ) {
$w("#image10").show();
}
} );
});
Thank you for the help. But then this would mean, that anyone with Admin role could change it, right?
Then I may have to look for another solution I guess. Because it should only be the owner. Thanks anyway for the help! Will copy the script for future matters.