Auth
The API has three independent account types, each with its own login route and cookie. There is no shared /auth namespace; account routes live under /users, /supplier and /admin.
Tokens and cookies
| Account | Login | Cookie | JWT secret | Payload |
|---|---|---|---|---|
| Traveller | POST /users/login | user_auth_token | JWT_SECRET | id, email, name |
| Supplier | POST /supplier/login | auth_token + supplier_auth_token | JWT_SECRET | id, email, name, isVerified |
| Admin | POST /admin/login | admin_auth_token | JWT_SECRET_ADMIN | id, email, role |
Supplier login sets two cookies with the same token: supplier_auth_token is httpOnly and used by Express, while auth_token is readable by the frontend's server components and middleware. Logout clears every auth cookie name.
POST /api/v1/users/login
Content-Type: application/json
{ "email": "traveller@example.com", "password": "secret" }{
"message": "Login successful",
"token": "eyJ...",
"user": { "id": "...", "email": "...", "name": "..." }
}Passwords are hashed with bcrypt (cost 10). Tokens are signed with jsonwebtoken.
Expiry units
JWT_EXPIRY is interpreted by jsonwebtoken as seconds. COOKIE_AGE is a cookie maxAge and is in milliseconds. Mixing them up produces tokens that outlive their cookie by decades.
Traveller endpoints
| Method | Endpoint | Auth | Purpose |
|---|---|---|---|
| POST | /users/register | Public | Create account and send verification email |
| POST | /users/login | Public | Login |
| POST | /users/logout | Public | Clear auth cookies |
| GET | /users/me | User | Current profile |
| PATCH | /users/me | User | Update current profile |
| GET | /users/:username | Public | Public profile by username |
| GET | /users | None in code | List users; treat as internal/admin-only |
| DELETE | /users/:id | Admin | Delete user |
Registration returns 201 and a user without setting an auth cookie. It creates a 10-minute verification JWT and emails ${FRONTEND_BASE_URL}/verify?token=....
POST /api/v1/users/register
{ "name": "Ada", "email": "ada@example.com", "password": "..." }Supplier endpoints
| Method | Endpoint | Auth | Purpose |
|---|---|---|---|
| POST | /supplier/register | Public | Register, send verification email |
| POST | /supplier/login | Public | Login |
| POST | /supplier/logout | Public | Clear auth cookies |
| GET | /supplier/verify/:token | Public | Verify email and log in |
| POST | /supplier/resend-verification | Public | Resend verification email |
| GET | /supplier/me | Supplier | Current supplier |
| PATCH | /supplier/me | Supplier | Update profile |
| PATCH | /supplier/update-password | Supplier | Change password |
| GET | /supplier/activities | Supplier | Own activities |
| GET | /supplier/bookings | Supplier | Bookings on own activities |
| GET | /supplier/revenue | Supplier | Revenue report |
| GET/POST | /supplier/payouts | Supplier | Payout history / request |
| GET | /supplier/reviews | Supplier | Reviews on own activities |
| GET | /supplier | Admin | All suppliers |
| GET | /supplier/:id | Supplier | Supplier details |
| PATCH | /supplier/:id | Admin | Update verification/suspension status |
| GET | /supplier/public/:id | Public | Public supplier profile |
| POST | /supplier/public/:id/contact | Public + Turnstile | Contact supplier |
A suspended supplier is rejected at login (403) and by supplierAuthMiddleware on every request.
Admin endpoints
| Method | Endpoint | Auth | Purpose |
|---|---|---|---|
| POST | /admin/login | Public | Admin login |
| POST | /admin/add | Admin | Create another admin |
| PATCH | /admin/verify-supplier | Admin | Set isVerified |
| PATCH | /admin/validate-activity | Admin | Approve/reject and publish/unpublish |
| PATCH | /admin/approve-listing | Admin | Approve, reject or suspend a listing |
| GET | /admin/analytics | Admin | Dashboard counts |
| GET | /admin/revenue | Admin | Platform revenue |
| PATCH | /admin/change-password | Admin | Change own password |
Shared password flows
These are registered at the API root, not under /users.
| Method | Endpoint | Body | Purpose |
|---|---|---|---|
| GET | /verify/:token | — | Verify a user or supplier email |
| POST | /forget-password | { email, accountType } | Send reset link |
| POST | /reset-password/:token | { password } | Reset password |
| POST | /logout | — | Clear auth cookies |
accountType is USER (default) or SUPPLIER. The same address can exist in both tables, so the API only looks in the table named by accountType. Reset tokens expire in 10 minutes and carry subject: "password-reset".
Middleware behaviour
| Middleware | Reads | Notes |
|---|---|---|
userAuthMiddleware | user_auth_token | Verifies with JWT_SECRET |
supplierAuthMiddleware | supplier_auth_token | Verifies with JWT_SECRET, then checks the supplier exists and is not suspended |
adminMiddleware | admin_auth_token | Verifies with JWT_SECRET_ADMIN |
authMiddleware | any auth cookie | Tries JWT_SECRET, then JWT_SECRET_ADMIN; also rejects suspended suppliers |