Suddenly sometime in the past week my login lightbox/ button that has worked without issues for months is not working. I have to refresh the page and then i am logged in. Not sure why this is happening suddenly. Can anyone see anything strange in my code or make sense of the console error logs that can give me any input on what is wrong. Live site URL is www.cryptodynamics.info/home
import wixUsers from 'wix-users';
import wixLocation from "wix-location";
import wixWindow from 'wix-window';
$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w("#button2").label = "Logout";
}
else {
$w("#button2").label = "Login";
}
} );
export function button2_click() {
//Add your code for this event here:
let email = $w("#email").value;
let password = $w("#password").value;
wixUsers.login(email, password)
.then( () => {
console.log("User is logged in");
} )
.catch( (err) => {
console.log(err);
} );
wixWindow.lightbox.close(); //--Doesn't seem like the code is reaching here
wixLocation.to("/account/my-account")
console.log
}
export function forgot_click() { wixUsers.promptForgotPassword(); }
how it looks when user logs out on a member restricted page
how it should look
@Chaim Kram There is still one issue, and that is when a user logs out on a member restricted page it opens the login/signup lightbox but it seems to break the lightbox formating. On non-member restricted pages it just logs out like it should.
@Chaim Kram That worked!! Still getting a few errors in console but it is working now.
@Chaim Kram Ok, changing the button. Doing this now.
@givemeawhisky I just tried your code, no change at all. I don't know what the issue is exactly other than the promise is not resolving after the user logs in, and that causes a cascade of errors and issues with my site. Been dealing with Wix support for 2 weeks, after first having them tell me MY code is wrong, NOT! Now they say they don't know what is going on, that it will be brought up with product development. In the mean time i am 3 weeks late launching this site (can't even do terminal testing cause the login system doesn't work) and i have partners that are talking about pulling out of the project because they are no longer confident that Wix is a platform that can even support a "REAL" business site. FML.
I have removed everything from the login code down to this, barebones basic login. And it DOES NOT WORK! It did until 2 weeks ago when Corvid rolled out.
import wixUsers from 'wix-users'; import wixLocation from "wix-location"; import wixWindow from 'wix-window';
export function button2_click() { let email = $w("#email").value; let password = $w("#password").value; wixUsers.login(email, password) .then( () => { console.log("User is logged in"); wixWindow.lightbox.close(); //--New location wixLocation.to("/account/my-account") console.log } ) .catch( (err) => { console.log(err); }); console.log("Made it to lightbox close"); }
export function forgot_click() { wixUsers.promptForgotPassword(); }
This is my page code for my members only page, this is where my login button is situated and when the user clicks on login, my custom login lightbox opens and the user logs themselves in and the lightbox closes and refreshes my members only page, which then kicks the code into working and changes the values of the page and the login button value becomes logout and all my hidden member parts are now shown as well.
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("#membersareaonlystrip").expand(); $w("#whitegapforfooter").hide(); } else { $w("#loginbutton").label = "Login"; $w("#membersareaonlystrip").collapse(); $w("#whitegapforfooter ").show(); } } ); export function loginbutton_onclick(event) { // user is logged in if(wixUsers.currentUser.loggedIn) { // log the user out wixUsers.logout() .then( () => { // update buttons accordingly $w("#loginbutton").label = "Login"; $w("#membersareaonlystrip").collapse(); $w("#whitegapforfooter ").show(); } ); } // user is logged out else { let userId; let userEmail; // prompt the user to log in wixUsers.promptLogin( {"mode": "signup"} ) .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("#membersareaonlystrip").expand(); $w("#whitegapforfooter").hide(); } ) .catch( (err) => { console.log(err); } ); } } export function profilebutton_onclick(event) { wixLocation.to(`/Members/${wixUsers.currentUser.id}`); } export function entermembersbutton_onclick(event) { wixLocation.to(`/members-area`); } export function myaccountbutton_onclick(event) { wixLocation.to(`/account/my-account`); } export function websiteupdatebutton_onclick(event) { wixLocation.to(`/website-update`); }
This is my own custom login lightbox code that closes and refreshes my members only page after the user logs in and the lightbox closes.
import wixUsers from 'wix-users'; import wixLocation from 'wix-location'; import wixWindow from 'wix-window'; $w.onReady(function () { $w("#forgotPassword").onClick( (event) => { //wixWindow.lightbox.close() wixUsers.promptForgotPassword() .then( ( ) => { // } ) .catch( (err) => { let errorMsg = err; //"The user closed the forgot password dialog" }); }); }); export function loginButton_onclick(event) { let email = $w("#email").value; let password = $w("#password").value; wixUsers.login(email, password) .then( () => { console.log("User is logged in"); wixWindow.lightbox.close(); wixLocation.to(wixLocation.url); //This reloads the same page and allows code to show hidden member parts. } ) .catch( (err) => { console.log(err); $w("#errorMessage").expand(); // You can delete this line if you are not going to add an error message. Use a regular text element set to 'collapse on load' from the Properties Panel. } ); }
All you need to do is to have your custom login lightbox refresh the page it is opened on after it closes so that the code on your page is kicked into gear, just exactly as you mentioned and told yourself the answer in your post above!
I have similar on my members only page where I have only my logo and a login button showing if members are not logged in.
Without my custom login lightbox refreshing the members only page once the member has logged themselves in and the login lightbox closes, then the page will not work as the code won't be called for the logged in user and the person will actually be logged in, however the page won't change from login to logout etc as the code is not started.
13 views and not a single response from Wix in over 2 weeks that a live site is down and support has no clue either. Why does this not surprise me. Where do you get this statement " Wix.com is a leading cloud-based development platform" when you can't even keep the most basic functions working?