Good morning,
I hope one of you will be able to help me with this issue.
I’ve had a problem for a few days on my website : I have a dynamic page for members (with member-specific informations) and members must log in to access it.
Since a few days, members connect (always with the same email address) and arrive on a page without all the informations from the database. Indeed, by looking in the database, a new line has been added for them.
The email address is the same, but wix create a new “profile” and they receive a new ID. The following times, they are redirected to this new profile, as if the old one no longer existed.
If I delete it, wix create another one when the member try to connect.
I have not changed anything in the code and therefore see no reason why it should not work.
(My background in coding is close to 0)
Thank you in advance for your help.
Here is the login code :
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#button27”).label = “LOGIN”;
$w(“#button3”).hide();
} );
}
// user is logged out
else {
let userId;
let userEmail;
// prompt the user to log in
wixUsers.promptLogin( {"mode": "login"} )
.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("profile")
.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,
"email": userEmail
};
// add the item to the collection
wixData.insert("profile", toInsert)
.catch( (err) => {
console.log(err);
} );
}