Duplicate registration prevention works in sandbox but not on live DB collection: HELP

Among the biggest absurdities that I came across on trying to build this site is the following:
I have managed to prevent duplicate registrations by matching same email usage on custom registration form in sandbox DB collection (as in Preview mode) yet when the site goes published a user using the same email can (of course register once) yet submit to the collection I am using to collect their contact info without prevention.

This is crazy as it should have been the case if the code was properly being executed not allow a user to submit anything into the collection in the first place as the email which is trying to use to register already exists.

On the contrary not only manages to submit but messes up everything else such us user id, assigned account number, etc.

The code from backend:

//data.js
import wixData from 'wix-data';
export function searchForDuplicates(value) {
// info contains the hook context
// use the collectionName property to use function for multiple collections
return wixData.query("Members")
.eq("email", value.email)
.find()
.then((results) => {
return results.items.length;
})
.catch((err) => {
let errorMsg = err;
});
}
export function Members_beforeInsert(item, context) {
// Calls routine to check if value already exists in the collection.
// If value not found, then save record.
// Else, if value is found, then reject this insert to prevent duplicate values.
// Note: concurrent inserts may result in duplicates.
// Pass context to searchForDuplicates to use for multiple collections.
return searchForDuplicates(context.collectionName, "email", item).then((res) => {
if(res > 0) {
return Promise.reject('This item already exists');
}
return item;
});
}

The code on site:

import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function () {
var min = 10000;
var max = 99999;
var bar = Math.floor(Math.random() *  (max - min + 1)) + min;
console.log(bar);
$w('#fxraccountnumber').value = "FXR" + String(bar);

$w('#submit').onClick( () => {
let email = [];
let fxraccountnumber = [];

email.push($w('#email').value);

// register as member using form data
wixUsers.register($w('#email').value, $w('#password').value, {
"contactInfo": {
"firstName": $w('#name').value,
"lastName": $w('#lastname').value,
"email": email,
"fxraccountnumber": $w('#fxraccountnumber').value

}
});

});
});

I have followed https://www.wix.com/corvid/forum/corvid-tips-and-updates/example-no-database-duplicates and every other available article out there without success.

I have used all available information from API, Tutorials videos, etc. - so no need to respond with a link to tutorials (don’t waste your time please). If you have something valuable to add in code/suggestions it would be very much appreciated.

Thank you in advance for your time.

Please read and take note of our Forum Guidelines.
https://www.wix.com/corvid/forum/community-discussion/corvid-community-guidelines

You need to understand how the datasets work in Wix and the different versions of them when working in Wix Editor or live site.

When you work in the Wix Editor you are working in the sandbox version of the dataset.

Whereas when yourself and users are viewing the published website, they are using the live version of the dataset.

Therefore, if you want the Wix Editor sandbox data to be applied to the live version, then you need to make sure that you sync your dataset before saving and publishing it.

See here for more info about it.
https://support.wix.com/en/article/syncing-data-between-sandbox-and-live-database-collections
https://support.wix.com/en/article/accessing-your-sandbox-and-live-database-collections
https://support.wix.com/en/article/displaying-database-content-on-a-regular-page

Finally, as stated on the Wix Users API section, you need to be testing any code with Wix Users on a live site for it to properly work for you.
https://www.wix.com/corvid/reference/wix-users.html

The APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality.

The APIs in wix-users can only be used once the page has loaded. Therefore, you must use them in code that is contained in or is called from the onReady() event handler or any element event handler.