Work · Case study 01
In developmentwhy:The refresh token lives in an HttpOnly cookie; only its hash is stored.
Jogaar
A role-based marketplace prototype where the account and session layer was built and tested first. Marketplace features are still in progress.
- Status
- In development
- Stack
- React
- Redux Toolkit
- Node.js
- Express
- MongoDB
- Mongoose
- Links
- Source on GitHub (external site)
Problem
Service seekers and providers need separate, trustworthy access to the same marketplace. If roles and sessions are shaky, every feature built on top inherits the problem, so the account layer had to be right, and provably so, before listings and bookings could start.
Approach
Build the account and session layer first and cover it with tests, so that marketplace features inherit a known-good foundation instead of discovering auth bugs later.
Split the session into two credentials. Requests carry an access token as a bearer token; a separate refresh token is set as an HttpOnly cookie, out of reach of page scripts. The server stores only a hash of the refresh token, so a database leak doesn't hand out live sessions.
Enforce roles in one place on the server. Seeker and provider roles are strictly validated at registration and checked by reusable authorisation on protected routes; the client mirrors them with role-aware route guards and navigation for usability, not security.
Diagram · Session lifecycle
01Sign in
Password checked against a bcrypt hash; role strictly validated.
server02Two tokens
Access token for requests. Refresh token in an HttpOnly cookie; only its hash is stored.
HttpOnly03Requests
Access token sent as a bearer token; role checks run on the server.
bearer token04Refresh & rotate
Cookie exchanged for new tokens; the stored hash is replaced atomically.
rotation05Replay refused
A refresh token that was already used is rejected.
reuse check
Build details
Rotation with replay rejection
Each refresh atomically swaps the stored hash for a new one, and a refresh token that has already been used is refused. A copied cookie replayed after rotation fails instead of quietly opening a second session.
Hardening the boring parts
Passwords are hashed with bcrypt, production cookie settings are applied, and authentication endpoints are rate limited. None of it is novel; all of it is easy to forget.
One error shape
The API returns errors in a consistent JSON format, so the client handles failures in one predictable way instead of special-casing each endpoint.
Tests at three levels
Server unit and integration tests, client unit tests, and four Playwright authentication tests in Chromium. Integration and browser runs use a disposable local MongoDB, and GitHub Actions runs every suite.
Evidence
why:Snapshots are dated; follow the source to check them.
51 passing automated tests
36 server, 11 client unit, 4 Chromium
Snapshot as of Nov 2026Profile README (external site)
Regression checks run in GitHub Actions
Node 24, MongoDB 8.0 and Chromium; lint and production build included
Diagram · Automated tests by level
- Server (unit + integration)
- 36 tests
- Client unit
- 11 tests
- Browser (Chromium)
- 4 tests
Total: 51 tests
Limits & next
Current limits
- Service listings, search, bookings and dashboard tools are unfinished.
- Passing authentication tests do not make it production-ready.
What I’d improve
- Build service listings, search and bookings on top of the tested session layer.
- Complete production deployment and acceptance testing; until then it stays a prototype.
Session explorer
A local educational simulation with fake tokens. No real account or API requests.
Simulation · fake tokens, no network
Simulated clock
- Login(next)
- Access token
- Expiry
- Refresh
- Rotation
- Logout
Ready
Walk through a token-based session one step at a time and watch where each credential lives: in page memory, in an HttpOnly cookie, or as a hash on the server.
It follows the pattern used in Jogaar’s session layer. Everything is simulated: no real credentials, keys or requests.
Browser memory
JavaScript can read
empty
No access token
HttpOnly cookie
JavaScript cannot read
empty
No refresh cookie
Server database
Stores a hash only
empty
No active session