PROBLEMS WITH THE CODE FOR MEMBERS

Hello community!
I have created a section of members, but when clicking on “My Profile”, it goes to the same profile, it does not matter with the account login.

This is my code:

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

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

export function loginButton_click(event) {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#loginButton”).label = “Login”;
$w(“#profileButton”).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(“Spain_agents”)
.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(“Spain_agents”, toInsert)
. catch ( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w(“#loginButton”).label = “Logout”;
$w(“#profileButton”).show();
} )
. catch ( (err) => {
console.log(err);
} );
}
}

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

I APPRECIATE ANY HELP YOU CAN GIVE ME.

Try adding Wix Data to your code:

import wixData from 'wix-data';

As you do these in your code:

return wixData.query("Spain_agents") 
wixData.insert("Spain_agents", toInsert)

Thank you very much for your prompt response. I’ve tried and it reflects this error:

You only needed to add the ‘import wixData…’ part of the code at the top of the page.

The other two lines of code were just showing you the two lines in your code where you have used wixData and hence needed to have the import wixData too.

Go back to your original code in your first post and simply add the import wixData line only.