This is the code I am using. When I publish the website and test it, I can’t click the button. It doesn’t take me anywhere. I already created the dynamic page that the button should take me too.
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w("#button4").label = "Logout";
$w("#button5").show();
}
else {
$w("#button4").label = "Login";
$w("#button5").hide();
}
} );
export function button4_onclick() {
if(wixUsers.currentUser.loggedIn) {
wixUsers.logout()
.then( () => {
$w("#button4").label = "Login";
$w("#button5").hide();
} );
}
else {
let userId;
let userEmail;
wixUsers.promptLogin( {"mode": "login"} )
.then( (user) => {
userId = user.id;
return user.getEmail();
} )
.then( (email) => {
userEmail = email;
return wixData.query("Members")
.eq("_id", userId)
.find();
} )
.then( (results) => {
if (results.items.length === 0) {
const toInsert = {
"_id": userId,
"email": userEmail
};
wixData.insert("Members", toInsert)
.catch( (err) => {
console.log(err);
} );
}
$w("#button4").label = "Logout";
$w("#button5").show();
} )
.catch( (err) => {
console.log(err);
} );
}
}
export function button5_onclick() {
wixLocation.to(`/Members/Update/${wixUsers.currentUser.id}`);
}
Can anyone help?