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.