Hi, not an expert, but I’m trying to create a members area using code.
I have followed the articule publishe din WIX, used my mind set to change the little things.
But no luck.
My collection name is Profile.
Please help!!
These is the code I am using that does not crank!
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
$w.onReady( () => {
if (wixUsers.currentUser.loggedIn) {
$w(“#button10”).label = “Logout”;
$w(“#button11”).show();
}
else {
$w(“#button10”).label = “Login”;
$w(“#button11”).hide();
}
} );
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#button10”).label = “Login”;
$w(“#button10”).hide();
} );
}
// 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(“Profile”)
.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(“Profile”, toInsert)
. catch ( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w(“#button10”).label = “Logout”;
$w(“#button11”).show();
} )
. catch ( (err) => {
console.log(err);
} );
}
}
export function profileButton_click(event) {
wixLocation.to(/Profile/${wixUsers.currentUser.id}
);
}
import wixUsers from ‘wix-users’;
import wixWindow from ‘wix-window’;
$w.onReady( () => {
if (wixWindow.rendering.renderCycle === 1) {
if (wixUsers.currentUser.loggedIn) {
$w(“#button10”).label = “Logout”;
$w(“#button10”).show();
}
else {
$w(“#button10”).label = “Login”;
$w(“#button10”).hide();
}
}