Issues with coding members area

Hey everyone,

I used the code examples provided at Velo Tutorial: Building Your Own Members Area | Help Center | Wix.com in an attempt to customise my member area. I followed the instructions and used the code below, but the login function is not working at all and when it appears to it doesn’t work properly.

  1. First it worked, by logging me out and directing me to the logging page, but kept returning incorrect user id or password.
  2. I published again and this time the button is non responsive.

Thanks for any help.

CODE

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, $w) {
// 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});
}

-END

Hello Abraham,

The code seems to work fine!
Make sure you have the right events added for each button, for example the login button as follows:


regarding the issue of returning wrong Id or password, i suggest you make sure of your data (you have the right data stored to compare with ), then to try to copy the information from the database to check whether the function is working first.

Good Luck!
Massa