Hi! I am trying to make sure there is no duplicates mail address in custom registration by using .find().
I got the below error in the "return", what is the meaning??
TypeError: user.register is not a function at of532.js:21
~~~
Here is my code:
import wixData from 'wix-data'; import wixUsers from 'wix-users'; $w.onReady( function() { let user = wixUsers.currentUser; $w('#button2').onClick(() => { let usermail =[]; wixData.query("cand_reg") .eq("cand_email", usermail ) //input3 is the box for inputting mail address .find() .then((res) => { if (res.totalCount > 1) { // Internal Error more than one entry exists throw Error('Internal Error - more than one entry exists'); } else if (res.totalCount === 1) { throw Error('Duplicate user found, returning'); } //insert to collection here (no duplicate found) return user.register($w('#input3').value, $w('#input5').value, { //NOT WORKING "cand_reg": { "cand_firstName": $w('#input2').value, "cand_lastName": $w('#input1').value, "cand_email": $w('#input3').value, "cand_birthday": $w('#datePicker1').value, "cand_password": $w('#input5').value, } }); }) .catch((error) => { $w('#text24').show(); //NOT working: the error messages is always showing console.log(error); }) }) }); ~~~~
New to coding so it will be great if any one have some advises.
I have read the following for reference:
Thank you very much!!!
KANA
What is user.register supposed to be? Are you trying to register the user in this code, then you need to use this: https://www.wix.com/corvid/reference/wix-users.html#register
Plus, you can't use Wix Users if the user themselves hasn't actually registered themselves as a member on your site: https://www.wix.com/corvid/reference/wix-users.html
If you want to stop duplicates, then look at the following links and see if their code can help you with your requirements:
https://codequeen.wixsite.com/membership-dashboard
https://www.youtube.com/watch?v=yLCOqsVHhD0&feature=youtu.be (video for above page)
https://www.wix.com/corvid/forum/wix-tips-and-updates/example-no-database-duplicates
Plus, read about before insert data hooks here:
https://www.wix.com/corvid/reference/wix-data.Hooks.html#beforeInsert