import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';
import wixData from 'wix-data';
let passwordInfo;
let emailInfo;
let firstNameInfo;
let lastNameInfo;
let universityInfo;
$w.onReady(function () {
$w('#signupButton').onClick(function() {
let userUniversity = $w('#dropdown1').value;
let email =$w('#emailAddress').value;
let password = $w('#passwordInput1').value;
let firstName = $w('#firstAndLastInput').value;
let lastName = $w('#LastName').value;
passwordInfo = password;
universityInfo = userUniversity;
firstNameInfo = firstName;
lastNameInfo = lastName;
wixUsers.register(email, password, {
contactInfo: {
"firstName": firstName,
"lastName": lastName,
"userUniversity" : userUniversity
}
})
.then((result)=> {
let resultStatus = result.status;
wixLocation.to("/account/recs");
userInfo();
})
.catch( (err) => {
console.log(err);
$w("#successMessage").expand(); // You can delete this line if you are not going to add an error message. Use a regular text element set to 'collapse on load' from the Properties Panel.
} );
})
});
function userInfo() {
let user = wixUsers.currentUser;
let email = user.getEmail();
let toInsert = {
"_id": user.id,
"first_name" : firtnameInfo
};
wixData.insert("ACCOUNTINFO", toInsert)
.then( (results) => {
let item = results;
console.log(results); //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
}
I’m trying to insert data to my collection “ACCOUNTINFO” when a user registers( when they register it runs a function called userInfo() that inserts saved data) and I tested in the console.log, but it doesn’t show anything at all and never adds to the collection.