Hello,
We have a complex onboarding form on our website which saves our user’s data to a database. It seems when their data is saved to the form, there is a possibility that the database will MIX their data. Yes, as in combine two users who are saving around the same time. Then, it will actually populate one user’s data into another user’s form, so one user can see another user’s sensitive information. This is VERY scary for us, considering we have been using it for some time and our business has come to rely on it. Please, if anyone has any idea why this might be happening, we would really appreciate any and all input. I will copy some of our code below.
//Save function
function saver() {
$w("#dataset1").onReady(() => {
returnIndex = $w('#fullWidthSlides1').currentIndex
$w('#dataset1').setFieldValues({
'lastSlide': returnIndex,
'email': emails
})
let a = $w("#dataset1").save();
console.log(a);
console.log('Saved')
});
}
//Auto-saves form every 30 seconds
setInterval(saver, 30000)
//Save Form Button
$w('#button89').onClick(() => {
saver()
wixWindow.openLightbox('returningUser', {
"sendData": true
})
.then((data) => {
//Returns Results of Query & Sets All Fields to Query Data
if (data.continueOn === true) {
var secondItem;
console.log('Continue:', data.continueOn);
saver();
$w('#dataset1').onAfterSave(() => {
wixData.query("formOnboarding")
.eq("userId", id)
.find()
.then((results) => {
console.log("Aftersave:", results);
secondItem = results.items[0];
})
$w('#dataset1').setFieldValues(secondItem);
checker();
//Queries DB using current user & returns most recent entry
var firstItem
var returnIndex;
var returnSlide;
var returnSlideIndex
function slideFinder() {
if (firstItem.lastSlide !== undefined) {
returnSlide = firstItem.lastSlide
} else {
returnSlide = 0
}
}
wixData.query("formOnboarding")
.eq("userId", id)
.find()
.then((results) => {
firstItem = results.items[0];
console.log("Results:", results);
console.log("userId", id);
if (firstItem !== undefined) {
// if (user !== undefined) {
console.log('Returning User')
slideFinder()
//Shows lightbox to prompt returning user to continue if they have previously saved data
wixWindow.openLightbox('returningUser', { "sendData": false })
.then((data) => {
console.log(data.continueOn)
//Returns Results of Query & Sets All Fields to Query Data
if (data.continueOn === true) {
returnSlideIndex = parseFloat(returnSlide)
$w('#dataset1').setFieldValues(firstItem);
$w('#fullWidthSlides1').changeSlide(returnSlideIndex)
.then(() => {
checker()
})
} else {
console.log('Fresh Start')
$w('#dataset1').new()
}
})
} else {
returnSlide = 0
$w('#dataset1').new()
console.log("Newcomer Present")
}
})
Thank you, sincerely. This fix will be invaluable to us.