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