Insert works on preview but on on live version.

Hey there. So, I am trying to build a page where all forms can be autofilled with some information that the user inputs at signup. I created custom signup and login, and changed the My Account page to display and update that information. I created a Members database with all the fills I require, and from my signup form, I am trying to collect al input data to that database as well as actually signing up the user as member.

My issue is that, although when I sign up from preview mode, the Members database is updated, the live site will not capture signups.
Could someone help me?

My code for the Sign Up form is as follows:

import wixUsers from ‘wix-users’ ;
import wixWindow from ‘wix-window’ ;
import wixData from ‘wix-data’ ;
let registration;

$w.onReady( function () {
$w( “#register” ).onClick((event) => {
console.log( “Button was clicked” );
$w( “#errorMessage” ).collapse();
$w( “#emailExists” ).collapse();
if ($w( “#email” ).valid && $w( “#password” ).valid && $w( “#company” ).valid && $w( “#name” ).valid) {
registerPerson();
console.log( “Trying to register” );
} else {
$w( “#errorMessage” ).expand();
console.log( “Missing Information” );
}

}) 

});

function registerPerson () {
let email = $w( “#email” ).value;
let password = $w( “#password” ).value;
let name = $w( “#name” ).value;
let company = $w( “#company” ).value
let toInsert = {
“name” : name,
“company” : company,
“email” : email
};
wixData.insert( “Members” , toInsert)
.then( (results) => {
let item = results;
} )
. catch ( (err) => {
let errorMsg = err;
} );
wixUsers.register(email, password, {
contactInfo: {
“name” : name,
“company” : company
}
})

    .then((result) => { 
                wixWindow.openLightbox( "confirmation" ); 
    }) 
        . **catch** ((err) => { 

let errMsg = err;
console.log(err);
$w( “#emailExists” ).expand();
} );

}

You are not actually registering the member on the site before the insert . Its rejecting because at the time of insert the user is not a member and your permissions is set to site member only

You should restructure like this

function registerPerson () {
   let email = $w("#email").value;
   let password = $w("#password").value;
   let name = $w("#name").value;
   let company = $w("#company").value

   let toInsert = {
      "name": name,
      "company": company,
      "email": email
    };
 
    wixUsers.register(email, password, {
    contactInfo: {
         "name": name,
         "company": company
    }
    })
    .then( () => {
        wixData.insert("Members", toInsert)
        .then( () => {
            wixWindow.openLightbox("confirmation");
        })
        .catch( (err) => {
             let errorMsg = err;
             console.log(errorMsg);
        });
    })
    .catch((err) => {
         let errMsg = err;
         console.log(err);
         $w("#emailExists").expand();
    });
}

Hi Shan!

Thank you so much for your answer!

Although this is not what I wanted, because I need to approve new members, this has been so helpful cause it made me understand that the permits for the database that I got from a tutorial would not work in this example. I was so frustrate with the code that I forgot my custom database settings.

My only fear, because I have never worked with databases before, is making sure that all information is safely stored.

Also, this disconnect between Wix’s contact list and PrivateMembers databases and custom databases that are needed in these cases where you have to store further information about users, seem to make it impossible to have a single source of truth. All members will be duplicated in those databases and have different IDs. I don’t understand why Wix won’t let us use custom fields in PrivateMembers database.

Anyways, thanks again for your reply.