I’m trying to build out a members only set of pages in my wix site and wanted to user a custom lightbox login page since the existing wix one is not customizable (beyond colors and fonts).
I want the lightbox to be served on page load for pages that are members only and only if the user is logged out. If the user closes the lightbox and doesn’t login, ideally I want them redirected to the last page they accessed. And should they try to access the member’s only page again, I want the lightbox served again.
I implemented the following for page code to serve the lightbox if the user accesses a members only page.
import wixUsers from ‘wix-users’;
import wixWindow from ‘wix-window’;
$w.onReady( function () {
let user = wixUsers.currentUser;
if (wixUsers.currentUser.loggedIn) {
wixWindow.openLightbox(‘MemberLoginLightbox’);
} else {
wixWindow.openLightbox(‘MemberLoginLightbox’);
}
});
The above code is not serving the lightbox at all unfortunately.
Once the lightbox is active, I have the following code inserted in it:
import wixUsers from ‘wix-users’;
import wixWindow from ‘wix-window’;
$w.onReady( function () {
let user = wixUsers.currentUser;
if (wixUsers.currentUser.loggedIn) {
wixWindow.lightbox.close();
} else {
wixWindow.openLightbox(‘MemberLoginLightbox’);
}
});
$w(‘#MemberLoginSubmit’).onClick ( function () {
let email = $w(‘#MemberLoginEmail’).value;
let password = $w(‘#MemberLoginPwd’).value;
wixUsers.login (email, password)
.then ( ()=>{
wixWindow.lightbox.close();
})
});
This appears to function properly but I would ideally have the page redirect to the page the user was at last if they close the page with the X, but not sure what the code would be to do this.
Thanks in advance for any input you have.