Custom Signup Form username - 2 different attempts

I am currently having issues trying to allow my website to have users sign in through just a username. I’m building the sign up form and I currently have this functionality built:

export function button2_click ( event ) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
wixData . query ( “UsernameEmail” )
. eq ( “Username” , $w ( ‘#username’ ). value )
. find ()
. then (
( results ) => {
if ( results . length != 0 ){ // if we have more than one of this username we want a forced refresh.
console . warn ( “Username already in use” )
throw new Error ( “Username in use!” );
//wixLocation.to(wixLocation.url);
} else {
let payload = {
“Email” : $w ( ‘#input2’ ). value ,
“Username” : $w ( ‘#username’ ). value
}
wixData . save ( “UsernameEmail” , payload )
. then ( ( results ) => {
let item = results ; //see item below
} )
. catch ( ( err ) => {
let errorMsg = err ;
} );
}
}
)

I save the username and email into a dataset to preserve uniqueness of usernames to emails. I’ve tested this code the issue is that even if I have 2 of the same username the custom sign up form will still make a new user even if this function returns an error. I realize that these are two separate functions at work, but is there a way to completely halt wix from continuing executing any more code?

Also, I’ve attempted a different approach where I used the authentication.register() route, but the contactInfo parameter does not work, the code is:

let email = $w ( ‘#input2’ ). value ;
let user = String ( $w ( ‘#username’ ). value );
let pass = $w ( ‘#input1’ ). value ;
let emails = ;

emails . push ( $w ( '#input2' ). value ); 
**let**  options  = { 
    contactInfo : { 
        Username :  user 
    }, 
    privacyStatus :  "PUBLIC" 
} 

authentication . register ( email , pass , 
{ 
    contactInfo :{ 
        "Username" : user 
    } 
} 
). then (( registrationResult ) => { 
 **const**  status  =  registrationResult . status ; 
 // When the site is configured for automatic approval, status is "ACTIVE" and the member is approved and logged in. 
 console . log ( 'Member registered and logged in:' ,  registrationResult ); 

})
. catch (( error ) => {
console . error ( error );
});

the error thrown is:

Type ‘{ Username: string; }’ is not assignable to type ‘ContactInfo’. Object literal may only specify known properties, and ‘“Username”’ does not exist in type ‘ContactInfo’. It’s recommended you use a new variable, such as “let newVar = …” to make sure that all code completion work correctly.

But I know that Username is specified already in my contactInfo area.

Any assistance would be greatly appreciated I’ve been at this issue for a while - thank you.

When using wix - members authentication.register() there is a bug with contactinfo optional parameters/ field-names that have capital letters…
Use lowercase for your custom field value name. (Change “Username” to “username” in your code above.
The Wix team are investigation this bug…

Thank you for your quick reply. I took your suggestion into account,
I altered ‘Username’ to ‘username’ and also updated my Contact custom field accordingly. But my issues still persist.

Type ‘{ username: string; }’ is not assignable to type ‘ContactInfo’. Object literal may only specify known properties, and ‘“username”’ does not exist in type ‘ContactInfo’. It’s recommended you use a new variable, such as “let newVar = …” to make sure that all code completion work correctly.

Thank you for your help :slight_smile:

I get the same error above in the Wix Blocks editor for my backend code, but once built works fine… (See red line below…)