Database Problems

I’m having some issues. I created a sign up page, and form. I followed all the instructions in the YouTube video on how to do this from Wix. Everything worked fine, and while playing around with the Sign Up form, I realized a person can create the same account multiple times. So I searched for some codes to prevent this. And I found this code:

import wixData from ‘wix-data’;

export function users_beforeInsert(item, context) {
let p = new Promise(function(resolve, reject)
{
//create a query to look for items with the same name as the item we’re tring to insert
let username_q = wixData.query(“users”).eq(“username”, item.username);
//create a query to look for items with the same email as the item we’re tring to insert
let email_q = wixData.query(“users”).eq(“email”, item.email);
//create a query to look for items with the same name OR the same email as the item we’re trying to insert
let big_q = username_q.or(email_q);

	//run the query to count the number of items that match 
	big_q.count().then(count => 
	{ 
		if (count === 0) 
		{ 
			resolve(item); 
		} 
		else 
		{ 
			reject("count is more than 0, dups found!"); 
			
		} 
	}); 
}); 

//return the promise from the hook 
return p; 

}

Upon implementing this code, everything worked fine! While in Sandbox Mode/Preview Mode, the form works perfectly. New unique users can sign up, and if they try and sign up more than once, it is refused. So everything worked great! BUT…when I saved my work and published the page, I went to the LIVE site to try out the form on the LIVE site. Well, that’s where the issue is. On the LIVE site, the form just sits there. AND nothing gets sent to the database to be stored. However, when in Preview mode/Sandbox Mode everything works like it is supposed to. Any help please? I’m kind of at a stand still right now…

Hi James,
My guess is that you didn’t set permissions correctly.
Check out this article .
Roi

Nope. I’ve changed the Permissions Set to Form Submission. Still, it works in Preview/Sandbox mode…but doesn’t work in LIVE/Published mode. I also changed the Permissions Set to Custom Mode and played and played and played with it. Still the same result. For whatever reason, it works find in the Preview/Sandbox mode…but doesn’t do anything in the LIVE/Published mode.

My site: http://jamesevans1981.wixsite.com/evans/sign-up

Hi,
In the before insert Hook use are using query method, meaning reading information from the database collection. you set it to admin but in your case it should be set to anyone.
Please update in your progress.
Roi

1 Like

I will do that right now. Thank you! I’ll let you know how it goes…

It worked! Thank you so much!!!

Glad to hear it worked!
Roi