I'm currently using the standard wix login lightbox with a custom Login/Logout button.The problem i'm experiencing is once someone successfully logs in, the logon lightbox disappears and nothing happens after that. The user is logged in, but the page doesn't refresh therefore the user doesn't realize they're actually logged in because the button still says Login. It's only when the user hits refresh or clicks on a new link tab that the button changes to Logout. Any ideas? Anyone else having this issue? Thanks.
Here's the code i'm using:
Might be important to mention I have this code as a site code not just a page code so it can show up on every page.
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() {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout();
wixLocation.to("/")
.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("Profile")
.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("Profile", toInsert)
.catch( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w("#loginbutton").label = "Logout";
// $w("#profilebutton").show();
} )
.catch( (err) => {
console.log(err);
} );
}
}
Have you figured this out yet? I'm stuck trying to do this too! I did a wix.locationto() and I can redirect to another page, but my issue is that when they submit they go to an outside payment page, so basically the page may be moving forward but they don't ever see it!