RBAC & Session Cookie Authentication
Role-Based Access Control (RBAC) assigns permissions to roles, then roles to users. Combined with signed session cookies, you get a simple, secure auth system that works without JWT complexity.badmin
Hono + SQLite — full RBAC admin panel with session cookies.
Cruise Ship
Next.js + PostgreSQL — role-based business system with token sessions.
RBAC Data Model
The classic RBAC model has four tables:Schema Definition
Session Cookie Auth
Instead of JWTs, use signed session cookies — simpler, more secure for same-origin apps:Why Cookies over JWT?
Implementation with Hono
Route Protection
Chain middleware to protect routes:Session Versioning (Forced Logout)
When a user changes their password or gets disabled, bump theirsessionVersion:
requireSession checks the cookie, it compares the cookie’s version with the DB version. If they differ, the session is rejected.
Session versioning is the simplest way to force logout. No blacklist, no waiting for JWT expiry — just increment a number in the DB.
Loading Permissions into Session
On login, load all the user’s permissions into the session object:Frontend Permission Checks
Don’t rely only on backend — hide UI elements the user can’t access:Cruise Ship: Token-Based Sessions
For the cruise-ship system (Next.js + PostgreSQL), we used token-based sessions stored in the DB:Best Practices
- Signed cookies over JWT — Simpler, revocable, smaller payload
- Session versioning — Increment to force logout on password change or account disable
- Flatten permissions — Load all permission keys into the session object for O(1) checks
- Exclude sensitive columns — Never query
passwordHashinto session data - Cascade deletes on M2M — Role/user deletions should auto-clean associations
isSystemflag on roles — Prevent deletion of essential roles (Admin, SuperAdmin)- Frontend hides, backend validates — Frontend checks are UX, backend middleware is security
- Token sessions for distributed systems — When cookies can’t work across services, store tokens in DB
References
- Hono Cookie API
- badmin auth module — Full Hono + SQLite RBAC implementation
- cruise-ship auth — Next.js + PostgreSQL token sessions
