Skip to main content

Overview

EaseLMS uses Supabase authentication for API security. Most API endpoints require a valid Supabase authentication token in the request headers.

Authentication Flow

The API uses session-based authentication with Supabase:
  1. User logs in via the /api/auth/login endpoint
  2. Supabase creates a session and returns access tokens
  3. Subsequent API requests include the session cookie
  4. Middleware validates the session on protected routes

User Types

EaseLMS supports three user types:
  • user - Learners who can enroll in and take courses
  • instructor - Instructors who can create and manage courses
  • admin - Administrators with full system access

Login

Endpoint

Request Body

string
required
User’s email address
string
required
User’s password
string
required
Type of user attempting to login: user, instructor, or admin

Example Request

Success Response

object
The authenticated user object from Supabase
object
The Supabase session object containing authentication tokens

Example Success Response

Error Responses

Invalid Credentials

Status: 401 Unauthorized

Wrong User Type

If a learner tries to login through the admin portal:
Status: 403 Forbidden If an admin tries to login through the learner portal:
Status: 403 Forbidden
Instructors can login through the admin portal and will be granted access.

Making Authenticated Requests

Using Session Cookies

After successful login, Supabase automatically sets session cookies. Include these cookies in subsequent requests:

Using Authorization Header

Alternatively, you can use the access token in the Authorization header:

Checking Authentication Status

Protected endpoints will return 401 Unauthorized if the session is invalid or expired:

User Permissions

Different endpoints require different permission levels:

Public Endpoints

These endpoints don’t require authentication:
  • GET /api/courses (published courses only)
  • GET /api/courses/[id] (published courses only)

Authenticated User Endpoints

These endpoints require any authenticated user:
  • GET /api/enrollments (returns user’s own enrollments)
  • POST /api/enrollments (self-enrollment)
  • GET /api/progress
  • POST /api/progress
  • GET /api/profile

Admin/Instructor Endpoints

These endpoints require admin or instructor privileges:
  • POST /api/courses (admin only)
  • GET /api/courses?all=true (all courses including drafts)
  • GET /api/users (admin only)
  • POST /api/users (admin only)
  • GET /api/admin/stats (admin only)

Permission Denied Response

If a user lacks required permissions:
Status: 403 Forbidden

Signup

Endpoint

Request Body

string
required
New user’s email address
string
required
New user’s password
string
required
New user’s full name
string
required
Type of user account: user, instructor, or admin

Example Request

Logout

Endpoint

Example Request

Password Reset

Request Password Reset

Change Password

Row Level Security (RLS)

EaseLMS uses Supabase Row Level Security to protect data at the database level. The API includes two types of Supabase clients:

Regular Client

Used for user-scoped operations. RLS policies apply:
  • Users can only access their own enrollments
  • Users can only update their own progress
  • Users can only view their own profile

Service Role Client

Used for admin operations and bypasses RLS:
  • Admin user management
  • Cross-user enrollment operations
  • System-wide statistics
The service role key should never be exposed to the client. It’s only used server-side in API routes.

Security Best Practices

Never send authentication credentials over unencrypted HTTP connections.
If storing tokens on the client, use secure, httpOnly cookies or secure storage mechanisms.
The API validates user types on login to prevent unauthorized access to admin/instructor features.
Implement token refresh logic to handle expired sessions gracefully.
Keep SUPABASE_SERVICE_ROLE_KEY private and only use it server-side.

Next Steps

API Overview

Learn about API structure and response formats

Courses Endpoints

Start working with the Courses API