Can someone help me fix this logic error. It works fine as long as I just check the logged on user vs the email address in my data record, but I am unable to add an additional check to see if the logged in user is me, or has a role of admin? so that I can edit any record.
I tried both with && and || - in both cases, it falls through and does not disable, if not me or the same email as the logged on user.
// Check if logged in user matches email address in page
import wixUsers from 'wix-users';
//import wixData from 'wix-data';
let userRole = wixUsers.currentUser.role;
$w.onReady(function () {
const userDataset = $w('#dynamicDataset') ;// Dataset of the page
//.................................
wixUsers.currentUser.getEmail()
.then( (email) => {
if (userDataset.getCurrentItem().emailAddress !== (email && "me@me.com" ))
{$w("#update").disable();}
});
});
Tried it, still not working.
Should the "update" be enabled when you are logged on?
In that case, the code should be:
if ((email !== 'skcureton@me.com') && (email !== userDataset.getCurrentItem().emailAddress)) { $w("#update").disable(); } else { $w("#update").enable(); }
Still not working. I think I had trued this at some point, but won't swear it.
I tried adding another set of parens around the if part, but that didn't help. just grasping at straws.
// Check if logged in user matches email address in page
import wixUsers from 'wix-users';
//import wixData from 'wix-data';
let userRole = wixUsers.currentUser.role;
$w.onReady(function () {
const userDataset = $w('#dynamicDataset') ;// Dataset of the page
//.................................
wixUsers.currentUser.getEmail()
.then( (email) => {
if ((userDataset.getCurrentItem().emailAddress !== email) && (email !== 'skcureton@me.com' ))
{$w("#update").disable();}
});
});
try:
if ((userDataset.getCurrentItem().emailAddress !== email) && (email !== 'me@me.com))