Opening a Lightbox with an if/else statement

Hi,

I am trying to set a ‘My Account’ button to send my user to their member page if they are already logged in; if they aren’t, I want my custom login Lightbox to appear.

I have managed to successfully make the if/else statement work, when the outcome was to go to a page. However, I cannot seem to make the Lightbox open.

This is what I have so far:

import wixWindow from ‘wix-window’;
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;

export function button37_click(event) {
if (isLoggedIn) {
wixLocation.to(‘/real-shop’);

}  **else**  
        wixWindow.openlightbox("login"); 

} 

For clarification:
‘button37’ is the aformentioned ‘My Account’ button, I have just not changed the name.
I have used the page extension ‘real-shop’ as an example, as I am yet to make my members page.

I have made the Lightbox name simply ‘Login’, as I thought that is where I was going wrong but it seems not.

If anyone could point out my mistake I would be very grateful!

Many thanks,
Ben

Is your lightbox called ‘Login’ or ‘login’?

If it is ‘Login’, then that needs to be reflected in your code.

  wixWindow.openLightbox("Login");

if it is ‘login’, then that needs to be reflected in your code.

  wixWindow.openLightbox("login");

Are you just trying to do something like this?
Velo Tutorial: Building Your Own Members Area | Help Center | Wix.com

Also, where is your onReady function underneath your imports?
Wix Editor Elements ($w) - Velo API Reference - Wix.com

Hi,

Thanks for getting back to me.

What does the onReady function need to look like?

In regards to the members area, that is something I am looking to do, but not the reason I am confused!

Thanks again,
Ben

onReady looks like this.

$w.onReady(function () {

You can have a good read of the onReady function from the API reference page that I linked already. Wix Editor Elements ($w) - Velo API Reference - Wix.com

There are other ways of writing it too, like if you are wanting to perform actions straight away on a dataset for example, so you run the dataset onReady function within the pages onReady function so that you can do things straight away when the page and dataset is fully loaded.

$w.onReady( () => {
  $w("#myDataset").onReady( () => {    
    //rest of code.....

Anyways, as this is going off of what you are wanting to know, so for this code here you only are needing to know the basic used onReady function as shown on the Wix onReady code page.

import wixWindow from 'wix-window';
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';

$w.onReady(function () {

let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn; 

//rest of code.......