Hi, I had this working but now it has stopped..


I had the custom section working but now it has stopped and i cant see why? I have also tried linking everything to do with one subject together. I also want to be able to enter a target based on specific information from the client. I did this by entering it the database which then showed as read only in specific clients members area. However it is all messed up now. No idea what i am doing.

the code for the button, the profile button is not working anymore.

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();
}
else {
$w(“#button1”).label = “Login”;
$w(“#button2”).hide();
}
} );

export function button1_onclick() {
// 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();
} );
}
// 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(“ClientDatabase”)
.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(“ClientDatabase”, toInsert)
. catch ( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w(“#button1”).label = “Logout”;
$w(“#button2”).show();
} )
. catch ( (err) => {
console.log(err);
} );
}
}

export function button2_click() {
wixLocation.to(/ClientDatabase/Update/${wixUsers.currentUser.id});
}

I hope you can see by those.

Thank you :slight_smile:

Hi,
Do you get any errors when clicking the button? check the console.

Hi, thanks for the reply… Not that i am aware of, it just doesn’t do anything.

Hey! Could you elaborate more a bit? It seems that your code works, so I’m not sure what specifically is the problem.

Hi Adam, it’s ok now I sorted it last night. I started a new site because the other was so messy with needless databases. I found the problem to be I deleted the members database page so it the profile button wouldn’t link to it. #dontknowwhatiamdoing