This guide explains how to set up Supabase for the JavaDSA Learn LMS backend.
- Go to Supabase and sign up or log in.
- Click "New Project" to create a new project.
- Fill in the project details:
- Project Name: JavaDSA-LMS
- Database Password: Create a strong password and save it
- Region: Choose a region closest to your users
- Click "Create new project" and wait for the database to be set up (this may take a few minutes).
- After the project is created, go to Settings > API.
- You'll find:
- Project URL: Copy this value
- Anon Public Key: Copy this value
- These will be used for
SUPABASE_URLandSUPABASE_KEYin your.envfile.
Go to the SQL Editor in your Supabase dashboard and run the following SQL queries:
create table users (
id uuid primary key default gen_random_uuid(),
username varchar(255) unique not null,
email varchar(255) unique not null,
password varchar(255) not null,
created_at timestamp default now(),
last_login timestamp
);create table progress (
id uuid primary key default gen_random_uuid(),
user_id uuid not null references users(id) on delete cascade,
course_id varchar(50) not null,
sections_completed jsonb default '[]'::jsonb,
bookmarks jsonb default '[]'::jsonb,
notes jsonb default '{}'::jsonb,
progress_percentage integer default 0,
last_accessed timestamp default now(),
created_at timestamp default now(),
updated_at timestamp default now(),
unique(user_id, course_id)
);
-- Create index for faster queries
create index idx_progress_user_course on progress(user_id, course_id);-
Update your
.envfile in thebackenddirectory with:SUPABASE_URL=your_supabase_url_here SUPABASE_KEY=your_supabase_anon_key_here
-
Replace
your_supabase_url_hereandyour_supabase_anon_key_herewith the values you copied in Step 2.
In your backend directory, run:
npm install @supabase/supabase-js-
Start your backend server:
npm run dev
-
You should see a message indicating the Supabase connection status:
- ✓ Supabase connection successful
- ✗ Supabase connection failed (if credentials are incorrect)
id: UUID (Primary Key)username: Unique usernameemail: Unique emailpassword: Hashed passwordcreated_at: Account creation timestamplast_login: Last login timestamp
id: UUID (Primary Key)user_id: Reference to users tablecourse_id: Course identifier (e.g., "java", "dsa")sections_completed: JSON array of completed section IDsbookmarks: JSON array of bookmarked section IDsnotes: JSON object with section IDs as keys and notes as valuesprogress_percentage: Numeric progress (0-100)last_accessed: Last access timestampcreated_at: Record creation timestampupdated_at: Last update timestamp
- Register: Users can create accounts with username, email, and password
- Login: Users can log in with email and password
- Profile: Users can view their profile and progress
- Update Progress: Track completed sections
- Bookmarks: Save important sections
- Notes: Add personal notes to sections
- Progress Calculation: Automatic progress percentage calculation
-
Add the Supabase environment variables in your Vercel project settings:
SUPABASE_URLSUPABASE_KEY
-
Redeploy your backend application.
- Verify that
SUPABASE_URLandSUPABASE_KEYare correct - Check your Supabase project is active
- Ensure your IP is not restricted by Supabase
- This is expected if trying to register with an existing email or username
- Ensure the user is authenticated (token is valid)
- Check that the course ID is correct
- Verify the progress table exists with correct schema
For more information, visit the Supabase Documentation.