Check to see if a user already exists on signup - [No Extra DB needed]

I know this is a huge pain for a lot of us since we can’t read the wixCRM db yet. But I finally got something to work and think a lot of us could benefit from. Yes this is tracking signups, and allows you to prompt when someone has an existing account all without having to create a new db just to track it all.

Signup Lightbox: (there’s a lot of custom stuff I removed, just to keep it legible, just wanting to copy up the root of this procedure… I may have missed a closing “}” or something like that, just keep in mind…

Lightbox Signup:


import {doRegistration} from ‘backend/register’;

$w.onReady( function () {

 $w('#submit').onClick( () => { 
      doRegistration($w("#email").value, $w('#password').value, $w('#firstName').value, $w('#lastName').value, $w('#title').value, $w('#company').value, $w('#companySize').value, $w('#phone').value, site) 
        .then( (result) => { 
        console.log(result); 
        **if**  (result === "Confirmation Request Sent...") {  
              // Prompt to check inbox for confirmation email 
        } else { 
             // Prompt that there may be an existing account already, and a link to login 
        } 
 }) 

})


Here’s the linked backend code… backend/register. Basically I’m setting a return that can be read in the parent once the registration is accepted via the .then block.

backend/register.jsw


import wixUsers from ‘wix-users-backend’;

export function doRegistration(email, password, firstName, lastName, title, company, companySize, phone, site) {
return wixUsers.register(email, password, {
“contactInfo”: {
“firstName”: firstName,
“lastName”: lastName,
“title”: title,
“company”: company,
“companySize”: companySize,
“phone”: phone
}
} )
.then( (results) => {
wixUsers.emailUser(‘XXXXXXX’, results.user.id, {
“variables”: {
“name”: firstName,
“token”: results.approvalToken,
“site”: site
}
} );
return “Confirmation Request Sent…”;
} )
. catch ( (error) => {
return error;
});
}


So if the account already exists during registration, what I saw is that I’m being handed back an object from the erroring “return wixUser.register” return that includes some verbiage buried inside something like “ACCOUNT_UPDATE” or something. But when there is no account there, the return isn’t triggered and the code moves on, that’s when I can set a specific return to parent of “Confirmation Request Sent…” that I can read.

Read the string = No there’s no account and boom! Working pre-existing account check with no tracked DB to upkeep, and still not reading wixCRM.

1 Like

Good work on this PJ!

1 Like