Switching email on a collection

Hi,
I have this site that need to register in order to create a profile via a form to a dynamic dataset.
So the entry on the DDS is linked to the email and password used at registration.

Now the member just log in with is email and password and get to my site.
Let say he need to replace is email with a new one.
How should I proceed in order to the new email/password connects to the same entry that exists in my collection.
I tried different scenarios and every time I create a new member (new email and password), it creates a new line in my collection. I thought of copying the data for the link to my entry /ListeMembres/Update/2bebd85d-d9ee-4b27-a377-5aeaa17f17ab of the new entry as an example but can’t paste it to the same field in my old entry so it would link to it.

Any idea how I should proceed with doing this?

Thank you!

Pierre Lacasse
ibmretraitesqc

Simple don’t use their Email as the users unique identifier in your database.

Use their user ID instead.

Mike thank you for replying. Their User ID is the email.
When they registered to the site, they enter the User ID which is their email.
I guess I do not understand entirely the process.

Here is my Registering/LogIn
Anything I should change?

Thank you!

let userId;
let userEmail;

// prompt the user to log in with French panel 
let options = {"mode": "login", "lang": "fr"}; 
wixUsers.promptLogin(options) 
  .then( (user) => { 
    userId = user.id;         
    return user.getEmail(); 
  } ) 
  .then( (email) => { 
    // check if there is an item for the user in the collection 
    userEmail = email; 
	$w('#text26').text = "Bonjour " + email 
	$w("#text26").show(); 

    return wixData.query("ListeMembres") 
      .eq("_id", userId) 
	  
      .find(); 
	  

  } ) 
  .then( (results) => { 
    // if an item for the user is not found 
    if (results.items.length === 0) { 
      // create an item 
	    const toInsert = { 
    "_id": userId, 
		  "adresseCourriel": userEmail, 
    "autorisation": "À valider",//write label to evaluate application as a member 
      }; 
      // add the item to the collection 
     wixData.insert("ListeMembres", toInsert) 
       .catch( (err) => { 
         console.log(err); 
       } ); 
    } 
    // update buttons accordingly 
    $w("#button4").label = "Déconnexion de votre compte actuel"; 
    $w("#button3").show();  
    $w("#text24").show();  
    $w("#text26").show(); 
                 
  } ) 
  .catch( (err) => { 
    console.log(err); 
  } ); 

}
}

@ibmretraitesqc

So you are not using wix-users API to register users ? Instead you are just copying their email and password to a database ?

I thought I was using wix-users API to register. I am creating a new entry in the database based on the email used at Registering and then paste the rest of the info from a form on a Dynamic dataset. I never log passwords in my database.
I can give you access to my site if you want so you can see what I do

Thank you!

Pierre

I’m not sure what method you are using to register users. Anyway to update an entry in a database code something like this…

import wixData from ‘wix-data’;

$w.onReady( function () {

$w('#searchButton').onClick((event) => { 

//input1 is where the user enters their old email, change as necessary

let oldEmail = $w(‘#input1’).value;

//input2 is where the user enters their new email, change as necessary

let newEmail = $w(‘#input2’).value

//database1 is the name of your database, change as necessary

    wixData.query("database1") 

//change yourColumnFieldKey to whatever field key you are using in your database

        .eq("yourColumnFieldKey", (oldEmail)) 

        .limit(1) 

        .find() 

        .then((results) => { 

let searchResults = results;

            console.log(searchResults); 

let userDatabaseID = searchResults._id

let toUpdate = {
“_id”: (userDatabaseID),

//email is the field key in your database change as necessary
“email”: (newEmail),
};

            wixData.update("myCollection", toUpdate) 
                .then(() => { 
                    console.log("email changed"); 
                }) 

        }) 
}) 

})

Mike, thank I will have a look at it and see what I can do

Pierre
ibmretraitesqc