Users database problems

Hi I am having trouble with databases in the website I’m working on. I have created a users database, details database and a habit summary for a website I am collaborating on. The users log in, this uses the users database to create new accounts and verify users who are returning. The Details database is where they add all of their information such as height and weight etc. It’s a health and wellbeing website.

Finally the habit summary database is filled with their progress on different pages of the site and that is used to update the main page. I’ve written a lot of javascript for the site. However, when you log on many of the user input boxes aren’t available that are attached to the database. They’re are greyed out. Ideally if you lose weight you should be able to update this data and then your BMI is recalculated. The only data that has been correctly collected is mine and anyone else try’s to enter data they come up against these greyed out boxes. I don’t know if the site actually know who is logged in.

I know what primary keys are and have done some reading on references and have read up on dynamic pages. I get the feeling I should have read up a bit more on these areas before creating the databases in the first place or how wix handles them. Hindsight is a wonderful thing. I’d like to try and get the database working. I may have to start over but it means a lot has to be undone. I would rather not do that.

Sam

When you say a Users dataset, do you mean something like a Members dataset as in this tutorial?
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area

Plus, if you created your own custom login and signup lightboxes, then you can collect a lot of the user details on your signup form to begin with and then let them change or add anything, like in the tutorial linked above.

You don’t have to keep the tutorial purely for what it is shown for, you can change the profile page for anything that you want to use it for and to then let the member add, edit or change anything on the update page.

As for the datasets and the user inputs being greyed out, have you made sure that all the dataset modes and permissions are all setup correctly?
https://support.wix.com/en/article/working-with-dataset-modes-and-collection-permissions
https://support.wix.com/en/article/about-collection-permissions

Also, note that when you add the Wix Members app to your website, it will also add it’s own Members PrivateMembersData collection too which you can query if you wanted too.

Here are all the collection fields for that dataset and how you can query the fields etc.
https://support.wix.com/en/article/corvid-wix-members-privatemembersdata-collection-fields

To query it you will need to put in the full collection name in your code as shown below.

wixData.query("Members/PrivateMembersData")
        .eq("loginEmail", email)
        .find();
}

For more info about data query see here.
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html
https://www.wix.com/corvid/reference/wix-data.html#query

Thanks I’m going to go through all the tutorials you listed. I think what we’re starting to realise is that it all worked fine until we made the login and created member only pages. It most likely has something to do with permissions. All the code I’ve created works but I’m not as good when it comes to Databases. It’s all a learning curve.

I have made the Warrior details page dynamic now and added the MemberID to the URL as per the tutorial. The boxes are no longer greyed out. I have also made another page that is dynamic as well. It’s called Life Coaching and I have linked 3 fields from the Warrior page to this including MemberID as references plus five new fields as I felt that the warrior details database was getting to big. When I look the published site it says that the page doesn’t exist perhaps I’ve named the URL incorrectly. Also I can’t update the information in the warrior details.

What code have you got for each of the pages and what are the dataset settings and permissions for the forms etc. Please list each page separately so that the code doesn’t get mixed up if there is a lot of it.

My code is mostly about interactions and loading images. I will have a look at it carefully on the weekend and write back. Last day of school for me today. Just trying to get through the term and then I can work on the website again. I teach IT at high school. I’ve never made a website that has a database attached before.

I’ve been looking through everything. Firstly I didn’t create all of the pages. So that’s part of the issue. The turtorials were very helpful that you posted.

  1. We have a lightbox page for logging in to a users database. (This is the part I didn’t create.
  2. Then we have a registration page that takes in their info. I have made this dynamic. I have inlcuded a URL using the members warrior name. i.e. Mines cyberSam65.
  3. Then there’s a life coaching page which I made an update URL.

I think we may not need 3 databases. I could merge the users and registrant details. I’ve used referenced data in Life Coaching so that hopefully it will know who’s who. My code doesn’t query the database as yet. My code does add things to the databases such as the value of a radio button. This was then used to show the correct coloured ring on the main page.

Getting the database correct is the first issue I want to resolve. As the pages that link to it are the main focus at the moment.

I think the key maybe in this part of what you said

“Plus, if you created your own custom login and signup lightboxes, then you can collect a lot of the user details on your signup form to begin with and then let them change or add anything, like in the tutorial linked above.
You don’t have to keep the tutorial purely for what it is shown for, you can change the profile page for anything that you want to use it for and to then let the member add, edit or change anything on the update page.”

The lightbox is being used for login and goes to the user databas. Should I combine this with the register database. Then make an update page just for changing your weight etc.

Sam

On my website I have taken this tutorial and used it for my Members Only page which is the only place that Members can log themselves in and out of the website as I only show the button on this page and I never use Wix’s own Login Bar on my site.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area

So to begin with I will have a dataset called Members which I have kept all the same as the tutorial so that it is both easy to follow any code and it is easy to tell what that dataset is for. The same goes for element id names too, always try to change them to something relevant so that you can name them easily in your code and relate to where they are on the page easily, much better and quicker than having elements on your page with id names of text145 and button48 for example!

This is the code for my Members Only page which is based from the tutorial above.

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("#membersareaonlystrip").expand();
$w("#whitegapforfooter").hide();

}
else {
$w("#loginbutton").label = "Login";
$w("#membersareaonlystrip").collapse();
$w("#whitegapforfooter ").show();

}
} );

export function loginbutton_onclick(event) { 
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w("#loginbutton").label = "Login";
  $w("#membersareaonlystrip").collapse();
  $w("#whitegapforfooter ").show();
  
} );
}
// user is logged out
else {
let userId;
let userEmail;

// prompt the user to log in 
wixUsers.promptLogin( {"mode": "signup"} )
.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("#membersareaonlystrip").expand();
$w("#whitegapforfooter").hide();

} )
.catch( (err) => {
console.log(err);
} );
}
}

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

export function entermembersbutton_onclick(event) {
wixLocation.to(`/members-area`); 
}

export function myaccountbutton_onclick(event) {
wixLocation.to(`/account/my-account`); 
}

export function websiteupdatebutton_onclick(event) {
wixLocation.to(`/website-update`); 
}

This is my code that is on my lightbox for login. I have the lightbox close after the user is logged in and refresh the page automatically as I need this so that the code on the existing Members Only page is rerun and makes the button label change and my hidden member elements show etc.

If you are moving the user onto another page after they have logged in then simply change the URL to whatever page you want the user to go to.

So in theory simply change the URL on this line to the page that you require.

//Change From This
wixLocation.to(wixLocation.url);
//This reloads the same page and allows code to show hidden member parts. 
 
//To Your Own Page....
wixLocation.to("/account/my-account");
//Change the URL ending to whatever page you want to send the user to after they log in.

Login lightbox code

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';

$w.onReady(function () {
 $w("#forgotPassword").onClick( (event) => {
    //wixWindow.lightbox.close()
   wixUsers.promptForgotPassword()
   .then( ( ) => {
   //
   } )
    .catch( (err) => {
    let errorMsg = err;  //"The user closed the forgot password dialog"
    });
 });
});

export function loginButton_onclick(event) {

 let email = $w("#email").value;
 let password = $w("#password").value;

 wixUsers.login(email, password)
   .then( () => {
     console.log("User is logged in");
     wixWindow.lightbox.close();
     wixLocation.to(wixLocation.url);  //This reloads the same page and allows code to show hidden member parts.
   } )
    .catch( (err) => {
     console.log(err);
     $w("#errorMessage").expand();  // You can delete this line if you are not going to add an error message. Use a regular text element set to 'collapse on load' from the Properties Panel.
   } ); 
}

This is the code for my own custom lightbox for signup.

This works perfectly and closes after registering details before moving users to signup status page, then both names will be saved in contacts and once site member is manually approved the member details will be added to ‘members’ database.

On my signup lightbox I am only collecting the users first and last name along with their email and password, however you can add whatever you want to collect here, just make sure that you have a user input for it and you add it to the contactInfo part of the code below.

Also, make sure that if you have any custom fields in your contacts, then these must be the same in the code that you use too.
https://support.wix.com/en/article/adding-custom-fields-to-contacts

Signup Lightbox Code

import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';

$w.onReady(function () {
    
    $w("#registerButton").onClick( (event) => {
        
   let email = $w("#email").value;
   let password = $w("#password").value;
   let first = $w("#firstName").value;
   let last = $w("#lastName").value;

   wixUsers.register(email, password, {
       contactInfo: {
        "firstName": $w('#firstName').value,
        "lastName": $w('#lastName').value,
       }
      } )
      .then( (result) => {
        let resultStatus = result.status;
  wixWindow.lightbox.close();
  wixLocation.to("/sign-in-status");  //Change the URL ending to whatever page you want to send the user to after they log in.
      } );     
    } );
    
});

if you look here at the Wix Register API reference and scroll down to ‘Register a user as a site member with registration options’, then you will see a code example of adding more variables for user inputs etc.

I have kept the signup form simple and easy for users to complete as I have kept the profile page like in tutorial from before that my users can use to change or edit or add anything to on that page instead of overcrowding my signup lightbox.

However, it is your own choice, if you want users to enter more info when they sign themselves up then add it to your lightbox etc. If you are happy with them just doing it on another page after they have signed up, then just keep it like the profile page etc.

Just remember that you can add anything you want onto that profile and update profile page, you don’t have to keep it as profile and you can do whatever you want on that page.

The first time a user signups up then their will be nothing displayed on their profile page other than their first and last names and email address, as that is all I collected on my signup lightbox.

Then the users can simply go to their update page and add whatever they wish to fill in on that page, it is not a requirement on my site.

Then once they have finished adding or editing anything, they simply save the new data and get taken back to their own member page which shows the updated info etc and all those new or updated user inputs will be saved in my Members dataset.

I have created my own wix site so that I can try out the tutorial https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area .
I understand most of the tutorial even some of the code for querying. I’m just getting quite overwhelmed by the enormity of what I’ve taken on. I started out just making interactions. Much of the login pages were already done. Databases were made. I came in after some of this was already done. I started connecting fields to the database etc. It seemed to work fine. Then my friend created the lightboxes for logging in and then what I’d worked on didn’t work the same anymore. I’m the only member with any details in the register database and I can’t update the details on that page anymore. Ie I want to change my weight and it won’t let me do that. Says there is an error trying to save. (I added messages to the submit button so I knew what was going on.)
Now my friend who I’m doing this for and I realise I should have been there from the beginning. Then I would have created all of the things we needed from scratch. The original registration page with the warrior details was a regular page first then I made it dynamic and followed the naming conventions etc for creating a unique URL. I think that page should have been created in the members section and then made dynamic. Maybe this is the issue.
I’m really struggling with this and I don’t know anyone is Australia who know’s wix. You’re the only person who has replied to me. Sam

I am going to keep trying. I just created two dynamic pages connected to a database and it worked. The URL’s are different one is an update page. Both pages are under member dynamic pages. I still have a way to go but this is a start. I will try and replicate this on the actual site and see if I can get it to work.

Sometimes it is much quicker and easier just to do it yourself so you know what you are doing and that everything works as it should.

It is okay taking over from somebody else if they are working the same as yourself and have the same understanding etc, however if you are both on different wavelengths or pages so to speak, then you are both going to have different ways of doing things.

So best to work together on things and follow tutorials where you can so it is already done for you and can help guide you along the way, It will get much easier the more you can manage to get done and do yourselves.

If you get stuck with coding issues then simply post another question in this forum again.

If you get stuck with something within the Wix Editor or a Wix app, then you are best suited going through Wix Support. - https://support.wix.com/en/about-wix/contacting-wix-support

Also, keep an eye on the Support pages.
https://support.wix.com/en/ and https://support.wix.com/en/corvid-by-wix/basics

if you are really stuck, then you can always try Wix Arena to get somebody to do it for you.
https://www.wix.com/arena/web-designers/1

Plus, I am sure that there are many Aussie people who know Wix and are in Australia, just got to reach out and find some, have a look around different places or internet search, am sure there are plenty of Wix designers in Australia.

Although if you or them are a cricket fan, I would expect to find a few of them in the pub drowning their sorrows after the World Cup loss and especially with the Kiwi’s in the final too :wink:

It doesn’t matter where the help is coming from. I was so frustrated that I was thinking of paying someone to fix it. You’ve been so helpful guiding me in the right direction. I’m not that much of a cricket fan I prefer tennis. Ash Barty was knocked out of Wimbledon so even that has gone down hill.

Oh so you are a fan of Nick Kyrgios and his ego then, however yes Ashleigh was knocked out by that unseeded USA player, would have been good to see another Aussie in the quarter finals since Dokic in what must be about 20 years or so now.

Although Australia ladies tennis isn’t that bad as they do alright especially with the addition of those two ladies from Russia and Croatia who now play for Australia, I can’t remember their names but the Croatian one is dating Nick I think. It would be good to have fresh new faces in the tennis finals instead of the usuals, especially with Nadal, Federer and Djokovic for the men, need your next Hewitt or Rafter.

Anyways, keep faith with what you are doing and it will all work out fine in the end, don’t get frustrated and want to throw it all in the bin, walk away and let somebody else do it!

For a start doing it yourself is saving money and you can have the accomplishment of knowing that when it is finished that you did it all yourself, obviously you will always have bits that are changing as you add new bits to the website or change and improve how things work on it etc, etc.

Plus, if there is an error or issue for example, you will be able to get back in there and get the problem fixed yourself without having to wait for somebody else to come along and have a look for you, especially if it was the weekend and they were not back into work until Monday.

Very Close to having it working. Gone back to having the no permission to go to a page when published. In preview mode the dynamic pages are working. I’ve checked the permissions. I followed the tutorial and a youtube video that was on the dynamic pages that helped a lot. I am using only the user database now.
I made the register page dynamic and connected it to the user dataset that the lightbox uses instead of my register database. Only issue is the "you don’t have permission to connect to this page error.’ I’m getting. This is the error that made me come on here in the first place. I may have to wind the website back to the time it was working then make the changes I made tonight. Only problem is the owner will lose a days work. What I’m doing is probably more important than a few videos at this stage. If the login doesn’t work then there’s no website.

Well the Dylan Alcot won Wimbledon so at least we got one aussie winner.