I have a user filling out data before signing up. If the user doesn’t sign-up, he still gets some information (thats what we use as a hook to get customers). If the user signs-up, I would like to save that data under that user, so he can return to it.
I implemented all of that, saving the data I want to save in the local storage (by wix).
Upon register, I try to update the _owner field in the db, which is not working properly.
code:
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import { local } from 'wix-storage';
import wixData from 'wix-data';
$w.onReady(function () {
$w("#submit").onClick( () => {
let email = $w("#emailInput").value;
let password = $w("#passwordInput").value;
let firstName = $w("#firstNameInput").value;
let lastName = $w("#lastNameInput").value;
console.log(`Registeting user ${firstName} ${lastName}`);
wixUsers.register(email, password, {
contactInfo: {
"firstName": firstName,
"lastName": lastName,
}
} ).then( (result) => {
let currentQuestionnaire = JSON.parse(local.getItem("currentQuestionnaire"));
currentQuestionnaire._owner = result.user.id
console.log(currentQuestionnaire._owner);
if ( currentQuestionnaire !== null ){
console.log("Updatign questionnaire owner")
console.log(currentQuestionnaire);
currentQuestionnaire._owner = result.user.id;
wixData.get("Questionnaire", currentQuestionnaire._id)
.then((item) => {
wixData.update("Questionnaire", currentQuestionnaire);
console.info(`updated questionnaire ${currentQuestionnaire.title}, data: ${currentQuestionnaire}`);
console.log(JSON.stringify(item));
wixLocation.to('/thank-you');
})
.catch((err) => {
let errorMsg = err;
});
} else {
console.log("No questionnaire found in cache");
wixLocation.to("/thank-you");
}
} );
} )
});
Why isnt this working (im guessing that _owner is a private field or something)? and how can I achieve this (I really rather avoid having 2 owner columns in the db)?