Hi everyone,
I’ve been stuck on something that feels like it should be simple: identify the next available lesson of a course. I recently moved my project over to Supabase and I’m still learning how to make the most of it.
My setup:
-
lesson table → contains all lessons, with an order_index column to determine the order of lessons within a course.
-
lesson_progress table → tracks lessons completed or in progress, with a column lesson_completed
Right now, I can easily tell:
What I can’t figure out is the best way to determine the next lesson to unlock. If anyone has ideas, or best practices for handling this in Supabase/Weweb, I’d really appreciate !
Thanks in advance!
Hi Melanie, welcome to the community 
You already have the data to know what’s completed vs not.
The simplest “next lesson” logic is:
• Sort lessons by order_index
• Filter out the ones where lesson_completed
is true
(or missing = false)
• Pick the first remaining one — that’s the next available lesson
In Supabase, you can run a query that joins lessons
with lesson_progress
for the current user, filters unfinished lessons, orders by order_index
, and limits to 1.
If you prefer “unlock only after finishing the previous”, you can instead get the highest completed order_index
and then return the lesson with the next index.
Makes sense?
Hi Agustin,
Thank you so much for your answer! That’s exactly what I had in mind, but I wasn’t sure whether it was better to handle the lookup in WeWeb (storing it in an array variable) or do it directly in Supabase using queries or functions. I’m used to working only with Xano APIs, so I’m still learning about Supabase queries, functions, and views.
Following your recommendations, I created a view in Supabase that joins lessons
with lesson_progress
and finds the next available lesson for each user. I then connected the view via a collection, and it’s now working perfectly!
Could you confirm if this is the recommended approach?