Greetings
I hope that all is well
I’m not master programmer but I had a similar issue where I wanted to ensure that every user that signed on my site had a unique email address and alias (username). After I figured out how to check for duplicates I ran into the case sensitive problem where ‘test@test.com’ would be different from ‘TEST@test.com’.
I forced all things inputed into my site to be lowercase in the database and this helped to keep things simple and avoid duplications in my check
Code forcing input to be all lowercase
//Run all checks and if good, register user to the site
$w ( ‘#submitButton’ ). onClick ( function ()
{
let email = $w ( '#registerEmail' ). value . toLowerCase (); //Get user email and turns it all lowercase to enter in the database
let password = $w ( '#registerPassword' ). value ;
let alias = $w ( '#registerAlias' ). value . toLowerCase (); //Get user alias and turns it all lowercase to enter in the database
authentication . register ( email , password ,
{
//Created custom 'alias' (username) field in CRM and I capture that data from my form and register it as well
contactInfo :
{
"Alias" : alias ,
},
privacyStatus : "PUBLIC"
})
. then ( ( registrationResult ) =>
{
console . log ( 'Registered New User!' , registrationResult );
//Go to Home page
wixLocation . to ( "/" );
})
//.catch((error) =>
// {
// console.error(error);
// });
})
Code to check for duplicates in the email or alias. If a user types in the input box and there is already a match then prevent them from submitting.
//Check Duplicate Alias; if duplicate exists show warning and keep email password box disabled
export function checkAliasDup ( event )
{
let alias = $w ( ‘#registerAlias’ ). value ;
console . log ( “Something Updated in Alias box” )
//Query for Existing Email in Collection; if found, do not allow user to register & generate 'duplication error'
wixData . query ( "MemberInfo" )
. eq ( "alias" , alias )
. find ()
. then ( ( results ) =>
{
//If the email field already exists; show error
if ( results.length > 0 )
{
$w ( "#aliasDupeerror" ). expand ();
$w ( '#registerEmail' ). disable ();
console . log ( "Alias Already Exists! Email field disabled!" )
}
**else**
{
$w ( '#registerEmail' ). enable ();
$w ( '#aliasDupeerror' ). collapse ();
}
})
}
//Check Duplicate Email; if duplicate exists show warning and kept password box disabled
export function checkEmailDup ( event )
{
let email = $w ( ‘#registerEmail’ ). value ;
console . log ( “Something Updated in Email box” )
//Query for Existing Email in Collection; if found, do not allow user to register & generate 'duplication error'
wixData . query ( "MemberInfo" )
. eq ( "email" , email )
. find ()
. then ( ( results ) =>
{
//If the email field already exists; show error
if ( results.length > 0 )
{
$w ( "#emailDuperror" ). expand ();
$w ( '#registerPassword' ). disable ();
console . log ( "Email Already Exists! Password field disabled!" )
}
**else**
{
$w ( '#registerPassword' ). enable ();
$w ( '#emailDuperror' ). collapse ();
}
})
}
Site: https://alvingwallace.wixsite.com/skreen/sign-up
Hope this helps or at least generate an idea ![]()