Prevent contact duplicates in custom registration?

Hello Brett,

Yea here is how to do it:

  1. Get current user email
  2. Query collection you are storing all the contacts in for that email
  3. If query returns something prevent registration(Redirect to another page, show error message, etc…)
  4. If query did not return something, insert into collection normally

Here is a template of how to do it with code:

import wixUsers from 'wix-users';

// ...

let user = wixUsers.currentUser;

user.getEmail()
  .then( (email) => {
    let userEmail = email;      // "user@something.com"
    
    wixData.query('YourCollectionName')
      .eq('emailField', userEmail)
      .find()
      .then((res) => {
          if(res) {
              return console.log('Duplicate user found, returning');
              //add error message to show or redirect here
          }
          //insert to collection here (no duplicate found)
      })
  } );

Hope this helps,
Majd