Help modifying user.getEmail() code to accept multiple e-mails

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();
          }
  });
});

Thank you! I knew there was a easy way to do it I just didn’t know how!

Do you leave the email address in this line of code?

(emaillist.indexOf(‘testuser@gmail.com’

@timstumbo Thanks, I meant to change that before posting. Here’s the corrected version:

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(email) >= 0) {
              $w("#addButton").show();
          } else {
              $w("#addButton").hide();
          }
  });
});

@tony-brunsman Thanks!