Site member email (login) not query correctly to collection

OK, here is my problem - I have a member login page, after logging in, a member profile tab is created - member clicks on the profile button and is directly, based upon their site member email, to a dynamic page where they can update, check their membership data.

My problem is after they sign in/create a login and become a site member, the code is supposed to query the collection (Membership) that I have uploaded with a csv file that contains the members email, address, etc… However, it keeps creating a new entry into the database even though it is populated w/ email addresses of all of my members.

The login buttons work just fine, you create the site member information, login and hit the profile page - but the only thing that is populated is the email address - none of the other things from the collection are pulled in and a new database entry is created. I can go in an update (I created an update button), populate and submit and the entry created with the site member signin is created just fine - but now I have 2 lines of the same information - the one I uploaded to the collection and the new one from the login.

I’m pulling my hair out!

Here is the code:

.then((user) => { 
			userId = user.id; 
			return user.getEmail(); 
		}) 
		.then((email) => { 
			// check if there is an item for the user in the collection 
			userEmail = email; 
			return wixData.query("Membership") 
				.eq("email", userEmail) 
				.find(); 
		}) 
		.then((results) => { 
			// if an item for the user is not found 
			if (results.items.length === 0) { 
				// create an item 
				const toInsert = { 
					"_id": userId, 
					"email": userEmail 
				}; 
				// add the item to the collection 
				wixData.insert("Membership", toInsert) 
					.catch((err) => { 
						console.log(err); 
					}); 

Thanks for your help!

my url is https://mnmsoa.wixsite.com/mnmsoa

Hi Kelly,

Here’s the thing…
Since you are importing data into the collection, you’re setting your own ‘Users database’.
This means that they are not really wixUsers, which is why the can’t read from a collection that has the following permission:


Here’s the error:

You can choose to change the permission to ‘Anyone’.
But I suggest reading this thread to get your head around the connection between wixUsers and your database.

Liran.

Thanks - but I only gave you part of my code… There is a login and folks login just fine w/ their Wix account - I don’t want this as anyone as this is a membership list and we don’t want anyone only site members to see and change.

After reading the thread you suggested - it does appear that there are a couple of steps left out of Velo Tutorial: Building Your Own Members Area | Help Center | Wix.com, so I’m going to do some more changes and see if I can get it to work.

Thanks - Kelly