How to restrict member logins to a set list of “Whitelisted Emails”
With a lot of help and the amazing support of my account manger I now have this working on my site. The steps used are not quite what was suggested by the Velo expert above. This is the way I have it working, though I’m sure there are several ways to achieve this.
Here is the code for you:
Backend Code
import wixData from ‘wix-data’; export async function isApproved(email) { const result = await wixData.query(‘Approved’).eq(‘title’, email).find(); return result.items.length; }
Page Code (Custom Sign Up Form)
import { isApproved } from ‘backend/verify.jsw’; $w.onReady( function () { $w(‘#verifyButton’).onClick(() => checkIfApproved()); $w(‘#editButton’).onClick(() => allowEdit()); }); function allowEdit() { $w(‘#emailInput’).enable(); $w(‘#signupButton’).disable(); $w(‘#editButton’).collapse(); } async function checkIfApproved() { const email = $w(‘#emailInput’).value; const approveStatus = await isApproved(email); if (approveStatus) { $w(‘#emailInput’).disable(); $w(‘#signupButton’).enable(); $w(‘#editButton’).expand(); $w(‘#notListedText’).collapse(); } else { $w(‘#notListedText’).expand(); } }
Steps to follow:
- Create a collection with the whitelisted email addresses
- Add Members Area to the site
- Use “Custom Form” as the Member Signup Form’s type
- Add to the form the needed functionality via the Editor’s elements and a bit of code - the general idea would be to force the user to go through a validation process prior to the process of completing and registration.
You will need to add a button to the form called verifyButton.
Happy coding!