Getemail() loading previous login email

Hello,
I have a strange issue on my website. One of the users signed up for an account using email1 and later logged out. The same user signed up for her partner with a different email account (email2), I believe the user used the same browser.
In my code when someone signed up I used wixusers.currentuser.getemail(). For the second signup instead of getting email2, the above statement is returning email1.

The same thing happened to me when testing but did not pay attention at that time.

Any idea why?

Any help would be really appreciated.

https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area
I used the above information to build by members area.

If you have used the code exactly as it is on the tutorial, then in theory it should let only the user with email1 or email2 login with the correct password that they used when they signed up/registered to your site.

Each member is given a unique ID, which you can find as a hidden field on your privatemembersdata, so the user of email1 should only be able to login by using email1 and their password and the same with email2 and their password.
https://support.wix.com/en/article/corvid-wix-members-privatemembersdata-collection-fields#id-_id

They should not be able to login with email1 and user email2 password or email2 and email1 password.

Check their fields in the dataset and look at the ID of each user to check that they are different, also check with the users of email1 and email2 and make sure that their passwords are different too. Yes they might have different email addresses, however if they both used the same password, then they will be able to login to either email as they both use the same password.

Finally, paste up your code from the tutorial so that we can check it, just in case you have added anything that might have affected anything.

This is the basic code from that tutorial which only needs the onclick event turned on in the properties panel. You can add more buttons to it if you wish if you want members to be able to access other pages from this screen too.

import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';

$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w("#loginButton").label = "Logout";
$w("#profileButton").show();
}
else {
$w("#loginButton").label = "Login";
$w("#profileButton").hide();
}
} );
export function loginButton_click(event) { 
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w("#loginButton").label = "Login";
  $w("#profileButton").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("Members")
.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("Members", toInsert)
.catch( (err) => {
console.log(err);
} );
}
// update buttons accordingly
 $w("#loginButton").label = "Logout";
$w("#profileButton").show();
} )
.catch( (err) => {
console.log(err);
} );
}
}

export function profilebutton_click(event) {
wixLocation.to(`/Members/${wixUsers.currentUser.id}`); 
}

I think you miss understood my issue.
When user1 logged into with email1, password1 the user got into his account with no problems. Then the user logged out and looged in as user2 email2, password2 and updated his profile. Both records in the table show unique ID’s. But email1 is some have loaded into user2’s profile instead of email2. Below is my code. It is pretty much same except with some changes.

$w.onReady(() => {
if (wixUsers.currentUser.loggedIn) {
$w(“#loginButton”).label = “Logout”;
$w(“#profileButton”).show();
wixUsers.currentUser.getPricingPlans()
.then((pricingPlans) => {
let firstPlan = pricingPlans[0];
let planName = firstPlan.name;
let startDate = firstPlan.startDate;
let expiryDate = firstPlan.expiryDate;
console.log(firstPlan);
console.log(planName);
//$w(“#text42”).text = firstPlan+" “+planName;
});
} else {
$w(”#loginButton").label = “Login/Sign-up”;
$w(“#profileButton”).hide();
}
});

export function loginButton_click(event) {
// check if user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixLocation.to(/home);
wixUsers.logout()
.then(() => {
$w(“#loginButton”).label = “Login/Sign-Up”;
$w(“#profileButton”).hide();

		}) 
		.catch((err) => { 
			console.log("error1" + err); 
		}); 
} 
// user is logged out 
else { 
	console.log("Logged out"); 
	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("Site_Members") 
				.eq("_id", userId) 
				.find(); 
		}) 
		.then((results) => { 
			// if an item for the user is not found 
			if (results.items.length === 0) { 
				// create a profile with just ID and email 
				const toInsert = { 
					"_id": userId, 
					"email": userEmail 
				}; 
				// add the item to the collection 
				wixData.insert("Site_Members", toInsert) 
					.catch((err) => { 
						console.log("error2" + err); 
					}); 
				wixLocation.to(`/Site-Members/Profile/${wixUsers.currentUser.id}`); 
			} else { 
				session.setItem("existingUser", true); 
				existingUser = true; 
			} 
			// update buttons accordingly 
			$w("#loginButton").label = "Logout"; 
			$w("#profileButton").show(); 
			let currentuserId = wixUsers.currentUser.id; 

		}) 
		.catch((err) => { 
			console.log("error3" + err); 
		}); 
} 

}
export function profileButton_click(event) {
let results;
let item
console.log(“PRofile Button clicked”);
console.log(“Existing USer” + session.getItem(“existingUser”));
wixData.query(‘Site_Members’)
.eq(‘_id’, wixUsers.currentUser.id)
.find()
.then(result => {
let items = results.items;
item = items[0];
console.log(item);

	}); 
if (session.getItem("existingUser") === false) { 
	wixLocation.to(`/Site-Members/Profile-Update/${wixUsers.currentUser.id}`); 
} 

wixLocation.to(`/Site-Members/Profile/${wixUsers.currentUser.id}`); 

}

Anyone have any thoughts on this?

The current implementation of the wixUsers.logout() function doesn’t currently allow you to take a follow on action upon logout, like redirect to another page. It just logs you out. If you are on a restricted page then you get the generic Wix login. Not always the desired outcome.

The current implementation of wixLocation.to () does the same thing. It doesn’t have a follow on action you can activate once the redirect has completed so that you can say logout.

https://www.wix.com/corvid/forum/community-discussion/this-is-how-to-logout-and-go-to-the-page-of-your-choice