wixUser PromptLogin Redirect

Hi, I am trying to check if the user is logged in or not on my website and if not, then show the login prompt. The code gets fired, but the website automatically redirects to the home page. Is this an error?

This is my code. Thank you!

if(!wixUsers.currentUser.loggedIn){
        wixUsers.promptLogin()
          .then( (user) => {
            return user.getEmail();
        } )
        .then( (email) => {
            let userEmail = email;  
            validateInputData()        // 
        } )
        .catch( (err) => {
            let errorMsg = err;             // "The user closed the login dialog"
        } );
    } else {
        validateInputData()
    }

When you say that it redirects to the homepage, is it that no matter which page you are on, you get redirected to the homepage? I’d like to help with that part first.

What you can also do is check once they’ve closed the prompt again to see if they’ve actually logged in (as a redundancy), rather than assuming that the login was successful.

wixUsers.promptLogin()
          .then( (user) => {
            
            if(wixUsers.currentUser.loggedIn){
              return user.getEmail();
            }                
        } )
       //Etc.

Hi, thank you for your reply. It is happening on only one page so far. When you open thecaninecompany. in/cake-for-dogs and click on any of the item, there is a buy now button. When the user fills the form and click buy now, it checks if the user is logged in or not. If not, it shows the login prompt. That’s when the user gets redirected to home page. It definitely shows the login prompt but it instantly redirects to homepage. I have tried the same code on other pages, it is working fine there.
I checked the console tab on Chrome while previewing the live site, I can only see one thing: Unrecognized feature: ‘vr’…