Simple Member Profile Page

I have spent more than 20 hours trying to something that in the end is going to make me feel real foolish.

I am trying to create a member profile page similar to the one that is in the Wix help center but have ran into a couple of problems.

  1. My code for the “Login” & “Profile” buttons is exactly like the Wix example with only the database name being different. However, after I do a new member through the login page it only adds the new member to my contacts and not the database.

  2. If I add the contact to the database manually and then run and click on the Profile button it tells me that the url cannot be found.

Can someone PLEASE help me with this? With each passing hour I slide further and further down my chair.

My database name is: Planmembers
My login page is: Loginpage
My dynamic pages are: Profile page and Profile Update page
My code is below:

Michael

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() {
// 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("Planmembers") 
				.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("Planmembers", 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() {
wixLocation.to(/Planmembers/${wixUsers.currentUser.id});
}

drbeatzsmash,

Thank you very much for your suggestion. After installing your suggested code I still have most of the same problems. The data from the new user I registered shows in contacts but not in the Planmembers database. Also, the “Login” and “Profile” buttons do nothing when clicked. The label in the Properties ID for each button is properly spelled and I have the “Profile” button linked to the “Planmembers (ID)” dynamic page but nothing works.

Can I impose on you for a suggestion again?

Just a thought, I have seen where you may have to undo any connections to database and save live/publish and then go back and reset the button connections.

Also check your permissions…read only or read/write

Hello Jeff,

Thanks for the suggestions but I have checked the permissions, made sure everything was in sync, did the undo buttons suggestion and still I am stuck.

  1. The “Profile” button does not work when the site is published. It gives me an error that the url could not be found (404) “Nothing there” error. BUT, in preview mode it does go to the correct page.
    [NOTE: when I try the published site and click the button my browser address bar shows:

…/Members/9bb009b0-bc58-43d2-adad-f1303d755235

Which in the database is the correct member ID for the person logged in.

I got this code from the Wix Editor help when I typed in “Member Profile Page” as the search. It is shown below.

ALSO: I checked the permissions but that wasn’t it. I even changed it to “everyone” just to see.

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() {
// 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() {
wixLocation.to(/Members/${wixUsers.currentUser.id});
}

Make sure you have the properties panel checked on the “tools” section at the top of your wix editor. On your login button look at the properties panel and make sure you have “onclick: loginButton_onclick” in the events section. This is the same for your profile button “onclick: profileButton_onclick”

I had this same problem and this worked for me. Hope this helps.

One last thought, make sure that your live data and sandbox data is synced. One way to check this is to publish, create a fake user, walk through the process. If it is working in the preview, and not in the published site, it maybe because that data is not synced.