It is called for the first time because twice === false. Then when it tries to be called again (I don’t know why), it won’t, because ‘twice’ gets the promise from wixWindow.openLightbox and it is not ‘false’ anymore…
I know it has been called twice, because I put a console.log inside the onClick function, and indeed it displayed twice…
I was opening my register lightbox directly from a button on my login lightbox.
To redirect the user to the register lightbox successfully I pretty much had to close the login lightbox with data saying “Open register lightbox” that was received by the original page.
i.e. here is my login button callback:
export function logIn_onClick ( ){ let userId ; let isLoggedIn ; let userRole ; let userEmail ;
**if** ( wixUsers . currentUser . loggedIn ){
wixUsers . logout ();
$w ( '#logIn' ). label = 'Log In' ;
$w ( '#myAccount' ). hide ();
$w ( '#tutorProfile' ). hide (). then (() => wixLocation . to ( "/" ))
}
**else** {
wixWindow . openLightbox ( "LOGIN" )
. then (( data ) => {
console . log ( "Data received from login" , data );
**if** ( data . loginSuccessful ) {
wixData . query ( "CustomMembers" ). eq ( "userId" , wixUsers . currentUser . id ). find ()
. then (( results ) => {
$w ( "#myAccount" ). show ();
$w ( "#tutorProfile" ). show ();
// if (results.items.length === 1) {
// userRole = results.items[0].role;
// console.log("User role post login", userRole);
// if (userRole === "Customer") $w("#myAccount").show();
// else if (userRole === "Tutor" || userRole === "Admin") {
// $w("#myAccount").show();
// $w("#tutorProfile").show();
// }
// } else console.log("Query result lenght neq 1", results);
})
} **else if** ( data . registerUser ) {
wixWindow . openLightbox ( "REGISTER" , data . context )
. then (( registerData ) => {
console . log ( "Register closed succesfully" );
})
}
})
}