Bespoke Member Login Button Error

Hello,

I have set up my own member login page rather than the normal one provided by Wix, it works but when I click login the button doesn’t do anything. The website is HJ Collection and it is on the Introducers Login lightbox.

The code I have used is:
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
import wixWindow from ‘wix-window’;
$w.onReady( function () {
$w(“#introloginforgotpassword”).onClick( (event) => {
//wixWindow.lightbox.close()
wixUsers.promptForgotPassword()
.then( ( ) => {
//
} )
. catch ( (err) => {
let errorMsg = err;
});
});
});
export function introloginButton_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”);
} )
. catch ( (err) => {
console.log(err);
$w(“#introloginerror”).expand();
} );
}

Would really appreciate any help here as I must have missed something.

You can’t just copy and paste code into your site without knowing or understanding what it does.

The basic login code for a login lightbox you have copied above works fine when used as it should be.

The first question would be have you added the onClick event to the login button in the properties panel for it?
https://support.wix.com/en/article/corvid-working-with-the-properties-panel

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) { //Make sure that you add the onClick event for it through the properties panel.

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

Also, another question would be have you got the Wix Members app added to your site?

As copying the example will take you to the My Account page from the Wix Members app, which is shown on this page here.
https://support.wix.com/en/article/adding-a-members-area-to-your-site

Hi, yes I have the members area and I have the onclick for the login button. This is why I can’t understand why it isn’t connecting. Is there anything else you can think of that would fix it? Thanks for your help.

I rewrote the whole code and now it works, must have been an error with a properties name etc. Thanks for your help.

Great. :grinning: