Register member and insert to dataset with prevent duplicate register

im new to coding need some advise for my site

import wixData from 'wix-data';
import wixUsers from 'wix-users';

$w.onReady( function() {
$w('#registerButton').onClick(() => {
let usermail =$w('#registerEmail').value;
   wixData.query("MemberData") 
       .eq("email", usermail ) 
       .find()
       .then((res) => {
if (res.totalCount > 1) {
throw Error('Internal Error - more than one entry exists');
           } else if (res.totalCount === 1) {
throw Error('Duplicate user found, returning');
           }
return wixUsers.register($w('#registerEmail').value, $w('#register2ndPassword').value, {
"MemberData": {
"firstName": $w('#registerFirstName').value,
"lastName": $w('#registerLastName').value,
"email": $w('#registerEmail').value,
"contact": $w('#registerContact').value,
"password": $w('#registerPassword').value,
"dob": $w('#registerDob').value,
"referral": $w('#registerReferral').value,
               }
           });
       })
       .catch((error) => {
           $w('#registerError').show(); //show error messages 
           console.log(error);
       })
})
});

i need my registration page with insert user input to custom dataset named MemberData and check to prevent duplicate and when successful redirect user to homepage

can anyone help me for this ?

Actually, if the email is duplicate, it will result in error.

No need to check

but there is no error message showing to user

Note: if the login result in error and the error === duplicate,
you can try login the user using their register email and password.

if the login credencial is incorrect, then prompt user to retry OR login

oic , so for my coding is all no problem right ?

@pvpbet88

return wixUsers.register($w('#registerEmail').value, $w('#register2ndPassword').value, {
"MemberData": {
"firstName": $w('#registerFirstName').value,
"lastName": $w('#registerLastName').value,
"email": $w('#registerEmail').value,
"contact": $w('#registerContact').value,
"password": $w('#registerPassword').value,
"dob": $w('#registerDob').value,
"referral": $w('#registerReferral').value,
               }
           })
/* ADD THESE CODE */
       .catch((error) => {
           $w('#registerError').show(); //show error messages 
           console.log(error);
// THEN ADD YOUR LOGIN EVENT TO TRY LOGIN
       })

and last i want to asking , how to let user password and 2nd password input must be same to submit the registration ?

and is there any code for redirect user after registration

if ($(‘#XXXXXX’).value === $(‘#YYYYYY’).value) {
//run the code of register
}

Please see “wix-location” in API

@certified-code so the coding is putting at which line . sorry im new to coding

If you need deeper coding, please reach out to an Wix Partner :slight_smile:

Note: We accept Chinese conversation

@pvpbet88 before “register” is run, wrap all the code of register and after inside this “checker”


but when i put they code you give just now become like this , how to solve it

can you copy and paste here?

import wixData from ‘wix-data’ ;
import wixUsers from ‘wix-users’ ;

$w.onReady( function () {
$w( ‘#registerButton’ ).onClick(() => {
let usermail =$w( ‘#registerEmail’ ).value;
wixData.query( “MemberData” )
.eq( “email” , usermail )
.find()
.then((res) => {
if (res.totalCount > 1 ) {
throw Error( ‘Internal Error - more than one entry exists’ );
}
else if (res.totalCount === 1 ) {
throw Error( ‘Duplicate user found, returning’ );
}
return wixUsers.register($w( ‘#registerEmail’ ).value, $w( ‘#register2ndPassword’ ).value, {
“MemberData” : {
“firstName” : $w( ‘#registerFirstName’ ).value,
“lastName” : $w( ‘#registerLastName’ ).value,
“email” : $w( ‘#registerEmail’ ).value,
“contact” : $w( ‘#registerContact’ ).value,
“password” : $w( ‘#registerPassword’ ).value,
“dob” : $w( ‘#registerDob’ ).value,
“referral” : $w( ‘#registerReferral’ ).value,
}
})
. catch ((error) => {
$w( ‘#registerError’ ).show(); //show error messages
console.log(error);
});

import wixData from 'wix-data';
import wixUsers from 'wix-users';


$w.onReady( function() {
    $w('#registerButton').onClick(() => {
 let usermail =$w('#registerEmail').value;
        wixData.query("MemberData") 
        .eq("email", usermail ) 
        .find()
        .then((res) => {
 if (res.totalCount > 1) {
 throw Error('Internal Error - more than one entry exists');
            }  
 else if (res.totalCount === 1) {
 throw Error('Duplicate user found, returning');
            }
 return wixUsers.register($w('#registerEmail').value, $w('#register2ndPassword').value, {
 "MemberData": {
 "firstName": $w('#registerFirstName').value,
 "lastName": $w('#registerLastName').value,
 "email": $w('#registerEmail').value,
 "contact": $w('#registerContact').value,
 "password": $w('#registerPassword').value,
 "dob": $w('#registerDob').value,
 "referral": $w('#registerReferral').value,
            }
        })
        .catch((error) => {
            $w('#registerError').show(); //show error messages 
            console.log(error);
       });
import wixData from 'wix-data';
import wixUsers from 'wix-users';


$w.onReady(function () {
 $w('#registerButton').onClick(() => {
 let usermail = $w('#registerEmail').value;
 wixData.query("MemberData")
            .eq("email", usermail)
            .find()
            .then((res) => {
 if (res.totalCount > 1) {
 throw Error('Internal Error - more than one entry exists');
                }
 else if (res.totalCount === 1) {
 throw Error('Duplicate user found, returning');
                }
 return wixUsers.register($w('#registerEmail').value, $w('#register2ndPassword').value, {
 "MemberData": {
 "firstName": $w('#registerFirstName').value,
 "lastName": $w('#registerLastName').value,
 "email": $w('#registerEmail').value,
 "contact": $w('#registerContact').value,
 "password": $w('#registerPassword').value,
 "dob": $w('#registerDob').value,
 "referral": $w('#registerReferral').value,
                    }
                })
                    .catch((error) => {
 $w('#registerError').show(); //show error messages 
 console.log(error);
                    })
            })
    })
})
1 Like

ok thanks , i will try for this