Members code help

I’ve been working on this project for a very long time, and I keep hitting a wall. I have two pages I need help on. Please check out my code and let me know what I’m doing wrong.
Thank you.


import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady(() => {
if (wixUsers.currentUser.loggedIn) {
$w(“#button1”).label = “Logout”;
$w(“#button2”).show();
$w(“#button3”).show();
$w(“#button4”).hide();
} else {
$w(“#button1”).label = “Login”;
$w(“#button2”).hide();
$w(“#button3”).hide();
$w(“#button4”).show();
}
});

export function button_onclick(event) {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then(() => {
// update buttons accordingly
$w(“#button1”).label = “Login”;
$w(“#button2”).hide();
$w(“#button3”).hide();
$w(“#button4”).show();
});
}
// user is logged out
else {
let userId;
let userEmail;

// prompt the user to log in
wixUsers.promptLogin({ “mode”: “login” })
.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(“Registration”)
.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(“Registration”, toInsert)
. catch ((err) => {
console.log(err);
});
}
// update buttons accordingly
$w(“#button1”).label = “Logout”;
$w(“#button2”).show();
$w(“#button3”).show();
$w(“#button4”).hide();
})
. catch ((err) => {
console.log(err);
});
}
}

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

export function button4_onclick(event) {
wixLocation.to(/Registration/);
}


In the above I’m attempting to show a login and signup button. Once logged in, the login button would change to a logout button, the sign up button would also disappear, and a profile button would emerge along with one other button. The signup button will be leading to a custom registration form. That is where my other issue is on code also.

Please see the code for my registration page below.


import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’; ;

$w.onReady( function () {
$w(‘#submit’).onClick(() => {

let Email = $w(“#email”).value;
let Password = $w(“#password”).value;
let Name = $w(“#name”).value;
let Phone = $w(“#phone”).value;
let Address = $w(“#address”).value;

                    Email.push($w('#email').value); 

// register as member using form data
wixUsers.register($w(‘#email’).value, $w(‘#password’).value, {
“contactInfo”: {
“Name”: name,
“Email”: email,
“Phone”: phone,
“Address”: address,
}

                        }) 
                        .then((result) => { 

let resultStatus = result.status;
});


The entries are submitting to the database, but the user is not being created and sent to my pending box. Any help would be greatly appreciated.
Thank you again.

Hello

Check this article out: Velo Tutorial: Creating a Custom Registration Form with Code | Help Center | Wix.com

I hope it helps!
Massa

Thanks for the reply Massa,
Not at all trying to be rude, but this is not helpful. I have already reviewed many of the tutorials on this subject including this one. I’ve taken pieces of code from them all and attempted to modify them to my needs. I am looking for someone to actually review my code, and let me know why it is not working.
Best regards!

@killam1586 would you please provide your editor/website URL for further help

@massasalah18

The website I am working on is https://www.freemasonsnh.org/

@killam1586 That will do. I’ll check it out and get back to you as soon as possible.

Thanks

Massa

bump

Hey @Jonathan Kilam
On the last image your missing some brackets
You need to close the brackets for submit button and another for the onReady page
code after line 27

 }); }); 

So, I tried this on the custom registration page with no success.


import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( function () {
let user = wixUsers.currentUser;
let userId = user.id;
let isLoggedIn = user.loggedIn; // true
user.getEmail()
.then((email) => {
let userEmail = email;
$w(“#email”).value = userEmail;

        $w('#submit').onClick(() => { 

let toInsert = {

“title”: $w(“#name”).value,
“email”: $w(“#email”).value,
“password”: $w(“#password”).value,
“phone”: $w(“#phone”).value,
“streetAddress”: $w(“#address”).value,
“city”: $w(“#city”).value,
“state”: $w(“#state”).value,
“country”: $w(“#country”).value,
“duesCard”: $w(“#duescard”).value,
“occupation”: $w(“#occupation”).value,
“businessTitle”: $w(“#title”).value,
“businessName”: $w(“business”).value,
“website”: $w(“#website”).value,
“district”: $w(“#district”).value
};
wixData.insert(“Members”, toInsert);
})
. catch ((err) => {
let errorMsg = err;
$w(“#error”).show();
});
});
});

latest attempt was with this code. Also unsuccessful…


import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( function () {
$w(‘#submit’).onClick(() => {

let emails = $w(“#email”).value;
let name = $w(“#name”).value;
let phone = $w(“#phone”).value;
let address = $w(“#address”).value;

                    emails.push($w('#email').value); 

                    wixUsers.register($w('#email').value, $w('#password').value, { 

“contactInfo”: {
“name”: name,
“emails”: emails,
“phone”: phone,
“address”: address,
}
});
});
});

try .catch to log the error message

wixUsers.register($w(’ #email ‘).value, $w(’ #password ').value, {
“contactInfo”: { name, emails, phone, address}
}).catch(err =>console.log(err));

btw name, or “name” : name is same

Don’t use the Admin email to register as it will be already register
Use some dummy email to register Check if the email is already register
By going to dashbord > cutomer management> contact list

I’ve tried every a bunch of stuff tonight. I can get the data to the with no problem, but still no member signup.

I am aware.

Below is my working perfectly code for my members login page which only shows a login button until the member logs themselves in. Then it will refresh the page and change the button to logout and display all the hidden member parts on the page. Copy and paste it into your editor and add any extra parts that are on yours.

// For full API documentation, including code examples, visit http://wix.to/94BuAAs

$w.onReady(function () {
//TODO: write your page related code here...

});
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": "login"} )
.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`); 
}

And this below is the code for my custom signup lightbox, use it and add the extra parts that are used in 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("/main-page");  //Change the URL ending to whatever page you want to send the user to after they log in.
      } );     
    } );
    
});

This works perfectly and closes after registering details before returning to home page, then both names will be saved in contacts and once site member is approved the member details will be added to ‘members’ database.

Does the page redirected after submittion?
Do you connect it to a dataset?
If yes use it on dataset before
So it will wait for the function to complete
Use a await instead of .then

Would you be willing to share your website URL?

Not currently set to redirect. I have a submitted message set currently.
Yes, it is connected to dataset, and working with submit button.
I’m not sure what you mean as to using it before?
Where are you suggesting a .then ??

UPDATE
The first members page with hidden buttons is mostly working thank you.
I just a refresh after the lightbox closes…
I am still trying to get the registration form working though.