Limiting members to certain pages within member pages

I am at a loss here and I am trying to figure out a workaround but need some help. I am creating a site for online courses. I want members to be able to signup and login as a free member to my site. Once they are members, they can purchase a course I have created. I will have 3 courses to begin with but I want to be able to add more courses. I have a courses, module, and lessons collection created. For example Course #1 will have 4 modules and 3 lessons per module. I have a members database created. How can I limit the member to only see the courses they purchased? Do I need a separate database for purchases? I am trying to create a page that allows users to select the course they are interested in buying once they are a member (i.e. you cannot buy the course unless you are a member first). Once they select the course they are interested in buying I have them submit a button with that course and send them to a buynow light box where there is a payal link to purchase. Within the paypal function I can redirect the user to a particular page, so my thought here is that I create a page that is a completed purchase page that only members can see and is not indexed and the member hits a button that says complete the purchase and a check box is checked that is a hidden element (i.e. all white in the top corner) that upon hitting completed purchase it updates the member profile to confirm purchase of course number 1. Because the member is already logged into the members area it will grant them access to this page. Once the member has completed the purchase they can go to a profile page and click on “my Courses” and only see the courses they have purchased and then click on that course. Once they go to that course, they are directed to the courses page that is linked to those specific modules. However when I do that now it is creating a separate entry for the member instead of updating the members row.

If I create a references column to purchased courses that references “course title” I cannot update that field unless I do it manually in the database. Even if I manually update it, I cannot “display” by that column in a table. What I am I missing here? I am also trying to automate as much of this a possible, so when I create a forth course, I can create a page to enter the data for course title, the different modules, and the different lessons. Maybe this part has to be manual on the database side of things. I can live with that if I can just limit my members to only the purchased courses. Any help would be great.

1 Like

Hi Matthew,
it sounds like you’re creating a cool website.

I wasn’t able to exactly follow the outline you gave above,
but let me try and point you in the right direction anyway.

I assume your “course” page is a dynamic page that shows the contents of a course.

this means that you can add your logic before the wix-code system loads that page.
you do that by using the “beforeRouter” hook on the router.js file.

you can read about routers and how to use hooks with routers here: Velo: About Data Hooks for Dynamic Pages | Help Center | Wix.com

the basic idea is to implement logic in that hook function to check if the current user has access to a specific course.

your code would grab the user’s ID from the incoming request, check if that user has indeed purchased the right course, and prevent the loading of the page if they didn’t.

this probably means that you need a purchased_courses collection, where you add an entry for every user that has purchased a course.

hope this points you in the right direction…
once you succeed in implementing this, I am sure there are lots of other users who would love to see how.

Matthew this is exactly the same setup that i want to do but im stuck at adding members accounts firstly! how did you get on?