Overview
SkillRise uses Clerk for authentication, providing secure user management with OAuth providers, magic links, and email/password authentication. The system implements role-based access control (RBAC) with three distinct user roles.User Roles
SkillRise implements three role levels through Clerk’s session claims:Student
Default role for all new users. Access to courses, quizzes, community, and analytics.
Educator
Create and manage courses, view enrollment data, and access quiz insights.
Admin
Full platform access including educator application review and system management.
Clerk Integration
User Model Schema
The User model syncs with Clerk through webhooks:server/models/User.js
The
_id field uses Clerk’s user ID as the primary key, ensuring seamless synchronization between Clerk and the application database.Webhook Handlers
Clerk Webhook Events
SkillRise listens to three Clerk webhook events to keep user data synchronized:server/controllers/webhooks.js
Signature Verification
Svix library verifies the webhook signature using headers to ensure authenticity.
Role-Based Middleware
Educator Protection
Middleware to protect educator-only routes:server/middlewares/authMiddleware.js
Admin Protection
Middleware to protect admin-only routes:server/middlewares/authMiddleware.js
Environment Variables
Required environment variables for authentication:.env
Security Features
Webhook Signature Verification
Webhook Signature Verification
All Clerk webhooks are verified using Svix signatures to prevent unauthorized requests and ensure data integrity.
Session-Based Authorization
Session-Based Authorization
Automatic Synchronization
Automatic Synchronization
User data is automatically synchronized between Clerk and the database, eliminating manual updates and reducing inconsistencies.
ID as Primary Key
ID as Primary Key
Using Clerk’s user ID as the primary key prevents ID conflicts and simplifies relationship management across the system.
Authentication Flow
Best Practices
Always Verify Signatures
Never process webhook events without signature verification to prevent security vulnerabilities.
Use Session Claims
Store role information in session claims for real-time authorization without database queries.
Idempotent Operations
Design webhook handlers to handle duplicate events gracefully.
Error Logging
Log all authentication errors for debugging and security monitoring.
Next Steps
Course Management
Learn how educators create and manage courses
Payment System
Understand the enrollment and payment flow