making a tailored members section

Hi there,
I’ve executed this:
https://www.wix.com/velo/forum/community-discussion/building-your-own-members-area/p-1/dl-6054cf472af6e9005e878d83-60549f90c013da002b01e28b-1?postId=5cbf52d8c98432006fbb4874&origin=notification&replyId=6054cf472af6e9005e878d83&commentId=60549f90c013da002b01e28b

I’m familiar with:

  • Database collections

  • Collection permissions

  • Page permissions

  • Dynamic item pages

  • Dataset Modes

  • Data Binding

This is the code I used on the login page:
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( “#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( “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( “#profileButton” ).show();
} )
. catch ( (err) => {
console.log(err);
} );
}
}

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

Any ideas why when I click on “My profile” it doesn’t load?
And why the update my profile doesn’t load the data?

I have done all the data binding.

I have also tried:

and bind this collection to each member collecting it from a dataset…

Any pointers will be really appreciated…

Thanks

Hi,

“My Profile” button is built up using the URL of your dynamic page

export function btnProfile_click_1(event) {
    wixLocation.to(`/User/Profile/${wixUsers.currentUser.id}`);
}

Here’s how the code looks like with my URL.


For the Update Profile page, your dataset should be set to ‘Read & Write’

hi Walter,
Thanks for the feedback.

Yes. My dataset is set to read and Write :frowning:

And Yes. I have already set this:

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

One question-- Why have you set User/Profile instead of Profile/ID?

Here’s my snap

That’s actually not necessary. By the way, could you check to ensure that your code is in the Master Page and not on the Page Code if your button is on the Header or set to ‘Show on All Pages’. Also check to see if your button onClick export function is still active in the properties panel.

Currently I have the code on the form page, not on the Master.
Nevertheless, if I head manually to the membersID or to the members All, Im unable to make the information display or update. :((((((((

You will need to add the code in the masters page code. Please share your page.

not Sure how to do that…newbie in the forum :))))

Maybe… I have something wrong with the collection…
I’ve left the default fields and will later customize them. Once I can make it work… :frowning:

I’ve just moved the buttons (Login/logout and My Profile) to the header and moved the code to the master page… and still nothing.