Hi,
Wanna ask if someone could help me to prompt a lightbox from code which is a custom login lightbox . This code prompts the default login that gives WIX which I don’t want that.
This is the code:
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() {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w("#button4").label = "Login";
$w("#button5").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("PrivateMembersData")
.eq("loginEmail", userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
"loginEmail": userId,
"email": userEmail
};
// add the item to the collection
wixData.insert("PrivateMembersData", toInsert)
.catch( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w("#button4").label = "Logout";
$w("#button5").show();
} )
.catch( (err) => {
console.log(err);
} );
}
}
export function button5_onclick() {
wixLocation.to(`/MemberProfile/Update/${wixUsers.currentUser.id}`);
}
Thanks