Authentication
HackPortal uses JWT in httpOnly cookies for sessions.
Flow
- Register —
POST /api/auth/register; password hashed with bcrypt; user created (no token yet). - Login —
POST /api/auth/login; credentials checked; JWT issued and set in an httpOnly cookie; session stored. - Authenticated requests — Cookie sent automatically; middleware validates JWT and attaches
req.user. - Logout —
POST /api/auth/logout; cookie cleared and session invalidated. - Session check —
GET /api/auth/mereturns the current user when the cookie is valid.
Cookies use secure in production and sameSite (e.g. lax for localhost, strict for production) so browsers send them only to the correct origin.
Related: Authorization, CSRF and CORS