Removing auto confirmation mail + lightbox after using wixUser.register()

Hi everyone !

I am looking for a solution to remove the auto confirmation mail + lightbox after the user click on submit button (it’s in french) :

That is very annoying because I want to redirect the user to his profile page straight after submitting and it’s impossible since he is not yet logged at this precise moment, even if I include it in the code ( I get error 403 since the page is set up to members only)

Here is my code :

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

$w.onReady(function () {
 
//related to forgot password
$w("#forgotPassword").onClick( (event) => {
   wixUsers.promptForgotPassword()
   .then( ( ) => {
 //
   } )
    .catch( (err) => {
 let errorMsg = err;  //"The user closed the forgot password dialog"
    });
 });
 
 //when clicking on register
 $w("#registerButton").onClick( (event) => {

 let email = $w("#email").value;
 let password = $w("#password").value;
 let first = $w("#firstName").value;
 let last = $w("#lastName").value;

// Implementing another database
 let toInsert = {
 "title": $w("#firstName").value,
 "prenom": $w("#lastName").value,
};

wixData.insert("members", toInsert)
  .then( (results) => {
 let item = results; //see item below
  } )
  .catch( (err) => {
 let errorMsg = err;
  } );
  
//registering the user
  wixUsers.register(email, password, {
       contactInfo: {
 "firstName": first,
 "lastName": last
       }
      } )
      .then( (result) => {
 let resultStatus = result.status;
 
 //logging in the user
  wixUsers.login(email, password)
   .then( () => {
     console.log("User is logged in");
     //redirecting to profile page
     wixLocation.to(`/members-first-connection/${wixUsers.currentUser.id}`);
   } )
 } );  
    } );
});

I will pray for someone who can solve this…
Thank you !

Hi,

After reviewing your code, I don’t see anything triggering the registration email or lightbox within the code that you provided.
I also see that you may have event listeners that are outside of the onReady Function. This may cause the listener not to respond if it is outside of the onReady function.
I would like to take a deeper look into the site to see if there is any settings that are triggering the email or lightbox elsewhere. Please provide us with the site name or URL so we can take a deeper look and help you disable the email and lightbox.

Thank you, we await your reply.
Edward

By the way, I used to have a custom sign up form before coding it, and now I can’t remove the “Custom Signup” lightbox :sweat_smile:

Hi Edward, Thank you so much for your answer ! Here is the URL : jeydi-group. com Thank you !

The Wix window that you are receiving here is nothing to do with your register or login code, it is a basic Wix window which appears sometimes to verify users.

See this Wix Support page for more info.
https://support.wix.com/en/article/email-verification-for-site-members

Also, when you use Wix Users API and the register() function, please note that the user is only having the choice of being manually approved and being a pending member until then, or if being automatically approved and being a active member.
https://www.wix.com/corvid/reference/wix-users.html#register

This however, does not mean that they are instantly logged in, they are only then classed as an active member of the site in the Wix Users API.

Therefore, in your signup lightbox code, you would need to add a close lightbox command and then an open login lightbox command, so that the user can go from the signup loghtbox to the login lightbox.
https://www.wix.com/corvid/reference/wix-window.lightbox.html#close
https://www.wix.com/corvid/reference/wix-window.html#openLightbox

Another option would be to have a collapsed element on your signup lightbox that is expanded after the member has registered themselves and then the signup lightbox is closed after a setTimeout.

Or you can simply set the lightbox to close after the user has registered themselves and you can take the newly signed up member to the members area if you have one and then have a login button that opens your login lightbox or you can use the promptLogin() function.
https://www.wix.com/corvid/reference/wix-users.html#login
https://www.wix.com/corvid/reference/wix-users.html#promptLogin

I have done similar on a site where I used this tutorial as a starting point for a members only page.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area

Then I used the signup lightbox code similar to yours.

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

$w.onReady(function () {
    
    $w("#registerButton").onClick( (event) => {
        
   let email = $w("#email").value;
   let password = $w("#password").value;
   let first = $w("#firstName").value;
   let last = $w("#lastName").value;

   wixUsers.register(email, password, {
       contactInfo: {
        "firstName": $w('#firstName').value,
        "lastName": $w('#lastName').value
       }
      } )
      .then( (result) => {
        let resultStatus = result.status;
  wixWindow.lightbox.close();
  wixLocation.to("/sign-in-status");  //Change the URL ending to whatever page you want to send the user to after they log in.
      } );     
    } );
    
});

NOTE:
Take out this line: wixLocation.to(“/sign-in-status”);
replace it with this line: wixWindow.openLightbox(“Login”);
at end of code if you want the lightbox to close and then to open the login lightbox.

This works perfectly and closes after registering details before moving the user onto the sign-in-status page, then both names will be saved in Contacts and once site member is approved the member details will be added to ‘members’ database, which is the same one from the tutorial.

On my members only page, I modified the code to suit the site as this.

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`); 
}

The login button on this page is the only place that members on this site can login and logout as well.

The login lightbox code is this.

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.
   } ); 
}

Note that you will see that I have used this in the Wix Location to() function to refresh the members only page after the login lightbnox is closed.

This needs to be done if you use the Members Profile tutorial from Wix as it is working on the basis that you are moving the user onto another page after they have logged in.

So when you come back to the first page, you are reloading the page and rerunning the code again which will then be able to know that the user is currently logged in.

However, as I wanted to stay on the same page I needed the page itself to be refreshed after the member is logged in so that the page code would run again and know that the user is logged in and to show all the members only parts and to make the button change to logout.

If you don’t refresh the page and stay on it, then it won’t register the user as being logged in and the button will not change to logout, it will stay on login etc.

To have it move to a new page then just do this.

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_click(event) {

 let email = $w("#email").value;
 let password = $w("#password").value;

 wixUsers.login(email, password)
   .then( () => {
     console.log("User is logged in");
     wixLocation.to("/account/my-account");  //Change the URL ending to whatever page you want to send the user to after they log in.
   } )
    .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.
   } ); 
}

Now here you can change the code here: wixLocation.to(“/account/my-account”);
To the page that you want to actually move to, which is your member profile page.

This is what I have done with a simple member profile button shown on the members only page after they have logged in.

export function profilebutton_onclick(event) {
  wixLocation.to(`/Members/${wixUsers.currentUser.id}`); 
}

So you would just need to change yours from:
wixLocation.to(/Members/${wixUsers.currentUser.id});
to yours as stated:
wixLocation.to(/members-first-connection/${wixUsers.currentUser.id});

Doing it my way, you can add much more user inputs in your signup lightbox and capture more of the users data there.

Whatever you obtain from the signup lightbox just add underneath the existing let last = … as well as in the contactInfo variable for register too.

Then once the user is approved all that info will be added to the members dataset from the tutorial and when they first login and view their own profile page, all that captured data will already be there to see.

They can then simply go to the update profile page to add or change anything and then save it again.

If you are only collecting the user email, password and first and last names on the signup lightbox, then that it all that they will see when they first visit the member profile page.

If you have changed your member signup settings to Corvid, then it shouldn’t matter as you are not using it.
https://support.wix.com/en/article/about-the-member-signup-form#corvid-form
https://support.wix.com/en/article/corvid-enabling-custom-site-registration

Going by the pic in the first link, go to the Custom option for signup and try clicking on the three dots in the circle here and choose remove custom form.
Then go back to Corvid and make sure that you are still on the right lightbox.