JWT vs Sessions: The Real Answer
This debate never ends on Twitter but the answer is simple: both are correct in the right context. The problem is most developers choose JWT because it sounds modern, not because it's the right tool.
- Sessions + HTTP Cookies: simplest, most secure, right for most LMS web apps
- JWT in Authorization Header: for APIs consumed by mobile apps or microservices
- JWT can't be invalidated instantly without a blacklist — a real risk if tokens are stolen
- Session invalidation is immediate: lock the account on the server and it's done
- Our recommendation: Sessions for web, JWT for APIs, Refresh Tokens for apps
| Criterion | Sessions | JWT |
|---|---|---|
| Immediate invalidation | ✓ Yes | ✗ Requires blacklist |
| Stateless | ✗ No | ✓ Yes |
| Scalability | Requires Redis | Simpler |
| Default security | ✓ Higher | Depends on implementation |
| Best for LMS web | ✓ Preferred | Secondary |
OAuth 2.0: Google, Microsoft, and Apple
Adding Google and Microsoft sign-in increases registration rates 30-40% in LMS platforms. Users hate filling out long registration forms.
- Google OAuth: most requested — easy to implement with passport.js or better-auth
- Microsoft OAuth: essential for institutions using Microsoft 365
- Apple Sign In: mandatory if you have an iOS app in the App Store
- Link multiple providers: let users connect Google and Apple to the same account
- Don't store the external access token in your DB unless you need it for API calls
RBAC: Role-Based Access Control
A typical LMS needs 4-6 roles. Each role has different capabilities that must be enforced at the API level — not just in the UI.
- Student: watch lessons, take tests, see own progress — nothing else
- Teacher: upload content, manage their students, grade submissions
- Admin: full management — users, courses, statistics
- Store permissions in the database, not JWT — allows instant permission changes
- PostgreSQL Row-Level Security enforces permissions at the database level
Security Fundamentals — Don't Skip These
The most common LMS vulnerabilities aren't sophisticated — they're neglected basics:
- Rate limiting on /login: without it, brute force can try millions of passwords
- CSRF protection: every mutation request needs a CSRF token if you use cookies
- Secure HttpOnly SameSite cookies: three mandatory attributes for session cookies
- Password hashing: bcrypt or argon2 — never MD5 or raw SHA256
- Email verification: don't allow full access until the email is confirmed
- Account lockout: after 5 failed attempts, pause the account for 15 minutes
Multi-Device Session Management
Students log in from phones, laptops, and tablets. Each session is independent — but users need to be able to see and terminate them.
- Store each session in Redis with user_id, device info, IP, and creation date
- 'Active Sessions' page: shows all currently connected devices
- 'Log out all devices' button: instantly deletes all user sessions
- Suspicious login alert: notification when login occurs from a new IP or country
- Session expiry: 24 hours for mobile, 8 hours for web — with renewal option
Complete Technical Stack
What we use at WANOVA for new platforms in 2026:
- Sessions stored in Redis (connect-redis + express-session)
- better-auth or Passport.js for OAuth strategies
- Argon2 for password hashing — newer and more secure than bcrypt
- express-rate-limit on all authentication routes
- Zod for input validation to prevent injection attacks
- PostgreSQL Row-Level Security as an additional database-level protection layer
