Skip to main content

Authentication

HackPortal uses JWT in httpOnly cookies for sessions.

Flow

  1. RegisterPOST /api/auth/register; password hashed with bcrypt; user created (no token yet).
  2. LoginPOST /api/auth/login; credentials checked; JWT issued and set in an httpOnly cookie; session stored.
  3. Authenticated requests — Cookie sent automatically; middleware validates JWT and attaches req.user.
  4. LogoutPOST /api/auth/logout; cookie cleared and session invalidated.
  5. Session checkGET /api/auth/me returns 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