Users database problems

Firstly we have a public page which you can click to either login or register.
Both pages go to their own lightbox connected to the user database. The Register lightbox has the paypal button on it.
On the login lightbox the button here is called let’s go. I want to then go to the dynamic page so that users can enter their data.
This is the point where it is going wrong. It will allow me to connect to the dynamic user page but wants me to connect to a particular useSa,r. I want it to just go to the page or at least the page of the currently login user. I’m using ID as the URL field. Some data is calculated and then once they have completed the form they click Update and this updates the user database. It works fine in preview but not the published version.

There is no code on the lightbox login page. Should their be? I’ve looked at login code today on two different youtube video. One is a video based on the tutorial you linked me intoon the first post. The second video is login code is for a lightbox. I’ve played around with both. I wasn’t sure whether we needed the code or not.

Also one other questions is there a difference between a member dynamic page and a dynamic page. When I was playing around and doing the tutorial on a brand new site I made. I had a section called member dynamic pages. On the site I’m working on with my friend I don’t see that section just dynamic pages. Is there a difference.

Sam

The no permissions error will not show on preview as you are using the admin view, whereas when it is done through the live version you are using the member settings and if you are trying to get access to somebody else’s page, then you won’t have the permission too.

Same with if you are trying to access a members only or password protected page, unless you are a member already logged in or have the password, then you won’t have the correct permissions to get access.

As for the lightbox pages, well yes the code for those lightboxes must go on the page tab for the lightbox themselves.

Plus, once the user has logged themselves in then simply move them onto their own member page by using the code that is already shown in the Wix Members page tutorial.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area

You just need to do something like this.

 wixLocation.to(`/Members/${wixUsers.currentUser.id}`);

Just make sure that you change Members to whatever you have called your page.

You can simply add that to your login lightbox code and change the code to suit

From:
wixWindow.lightbox.close();
wixLocation.to(wixLocation.url); 

To:     
wixWindow.lightbox.close();
wixLocation.to(`/Members/${wixUsers.currentUser.id}`); 

Finally, as for dynamic pages, simply have a read here and it will all be clear to you, however they are basically the same thing as they let you use the same one page layout to display different items from your dataset on other pages, the only difference with members pages is that they are only viewable by the unique user themselves.
CMS: Converting an Existing Page to a Dynamic Page | Help Center | Wix.com
CMS: Examples of Dynamic Pages | Help Center | Wix.com
https://www.wix.com/corvid/feature/dynamic-pages

I have created both a login using the member tutorial and the light box version to see if I can get either to work. Below the login page links to the lightbox. Then the update button links to the dynamic profile page in code.

import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
// For full API documentation, including code examples, visit http://wix.to/94BuAAs

$w.onReady(function () {
 
});

export function profileButton_onclick(event) {
  wixLocation.to(`/Members/Update/${wixUsers.currentUser.id}`); 
  //This isn't loading the member page.
} 


Lightbox

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

$w.onReady(function(){

})

export function loginNow_click(event) {
let email = $w(‘#loginEmail’).value;
let password = $w(‘#loginPassword’).value;
wixUsers.login(email,password)
.then(()=>{
console.log(“User is logged in”);
wixWindow.lightbox.close();
wixLocation.to(/Members/Update/${wixUsers.currentUser.id}); //This is supposed to go to to the profile page. But it just closes and goes back to the previous page.
})
}

I know that I’m missing something but I’m not sure what exactly. I have another login page but it’s using the generic member login and code but I prefer the light box version as that’s what the dr has on her site.

I’ve read most of your links and suggestions. I have tried to combine ideas from the wix member login with the lightbox. I’d actually like the profile button to appear only after they’ve logged in.

sam

This is the more traditional login version.

import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
// For full API documentation, including code examples, visit http://wix.to/94BuAAs

$w.onReady(function () {
 if(wixUsers.currentUser.loggedIn) {
    $w("#loginButton").label = "Logout";
    $w("#profileButton").show();
  }
 else {
    $w("#loginButton").label = "Login";
    $w("#profileButton").hide();
  }
 //TODO: write your page related code here...

});

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/Update/${wixUsers.currentUser.id}`);
}


This works okay but it always loads the first item in the database. So I log in and I get the first user in the database’s data and not mine. There’s only two people in the database. I’m the second one.


I needed to take a break from it. I needed to fresh eyes. My son has just gone to the US for the World Scout Jamboree. So now I’ve got sometime in the evening to work on it again.

Sam

hi, friends! im new user, and i havent programming knowladge, for people like me, its better if there is platform where we can get/buy some ready codes with explanation (simple explanation). It will save the time.
http://www.rahkarenovin.com
http://www.rahkarenovin.net

I’ve been using the forum and youtube and wix.api to find what I need. It’s been helpful. The tutorials posted here have been most helpful.

Thanks so much for all your help. Yesterday afternoon I finally got it to work. I have followed a number of youtube videos that are basically made to follow the tutorials linked here. What I got from that was helpful. They’d say something that was useful but was’t in the written tutorial. Now I can finish off other parts of the website that were held up because of the login’s and dynamic pages. Below is some of the work that I did in creating my own pages. I can see why things weren’t working better now.

I’m still having an issue. When I added the other textboxes to the database only the ones I originally connected to the database are working. The latter ones I connected this morning won’t update and I get an error message in the console.log.