I'm sure this is a simple fix but I can't figure it out. I have the code working for a single users e-mail address but I need it to work for multiple users instead of just the one. Here's the working code for the single user:
import wixUsers from 'wix-users';
$w.onReady(() => {
let user = wixUsers.currentUser;
user.getEmail()
.then((email) => {
if (email === 'testuser@gmail.com') {
$w("#addButton").show();
} else {
$w("#addButton").hide();
}
});
});
How do I change the code to accept multiple e-mail addresses?
Thanks!
Hi,
There are many ways to do this. This way defines an object with a number of emails, and then uses the indexOf function to see if the logged in user's email exists in that object.
import wixUsers from 'wix-users'; $w.onReady(() => { let emaillist = ['testuser@gmail.com','testuser@yahoo.com','testuser@hotmail.com','johndoe@gmail.com']; let user = wixUsers.currentUser; user.getEmail() .then((email) => { if (emaillist.indexOf('testuser@gmail.com') >= 0) { $w("#addButton").show(); } else { $w("#addButton").hide(); } }); });