Skip to content

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 ​

AccountLoginCookieJWT secretPayload
TravellerPOST /users/loginuser_auth_tokenJWT_SECRETid, email, name
SupplierPOST /supplier/loginauth_token + supplier_auth_tokenJWT_SECRETid, email, name, isVerified
AdminPOST /admin/loginadmin_auth_tokenJWT_SECRET_ADMINid, 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.

http
POST /api/v1/users/login
Content-Type: application/json

{ "email": "traveller@example.com", "password": "secret" }
json
{
  "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 ​

MethodEndpointAuthPurpose
POST/users/registerPublicCreate account and send verification email
POST/users/loginPublicLogin
POST/users/logoutPublicClear auth cookies
GET/users/meUserCurrent profile
PATCH/users/meUserUpdate current profile
GET/users/:usernamePublicPublic profile by username
GET/usersNone in codeList users; treat as internal/admin-only
DELETE/users/:idAdminDelete 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=....

http
POST /api/v1/users/register
{ "name": "Ada", "email": "ada@example.com", "password": "..." }

Supplier endpoints ​

MethodEndpointAuthPurpose
POST/supplier/registerPublicRegister, send verification email
POST/supplier/loginPublicLogin
POST/supplier/logoutPublicClear auth cookies
GET/supplier/verify/:tokenPublicVerify email and log in
POST/supplier/resend-verificationPublicResend verification email
GET/supplier/meSupplierCurrent supplier
PATCH/supplier/meSupplierUpdate profile
PATCH/supplier/update-passwordSupplierChange password
GET/supplier/activitiesSupplierOwn activities
GET/supplier/bookingsSupplierBookings on own activities
GET/supplier/revenueSupplierRevenue report
GET/POST/supplier/payoutsSupplierPayout history / request
GET/supplier/reviewsSupplierReviews on own activities
GET/supplierAdminAll suppliers
GET/supplier/:idSupplierSupplier details
PATCH/supplier/:idAdminUpdate verification/suspension status
GET/supplier/public/:idPublicPublic supplier profile
POST/supplier/public/:id/contactPublic + TurnstileContact supplier

A suspended supplier is rejected at login (403) and by supplierAuthMiddleware on every request.

Admin endpoints ​

MethodEndpointAuthPurpose
POST/admin/loginPublicAdmin login
POST/admin/addAdminCreate another admin
PATCH/admin/verify-supplierAdminSet isVerified
PATCH/admin/validate-activityAdminApprove/reject and publish/unpublish
PATCH/admin/approve-listingAdminApprove, reject or suspend a listing
GET/admin/analyticsAdminDashboard counts
GET/admin/revenueAdminPlatform revenue
PATCH/admin/change-passwordAdminChange own password

Shared password flows ​

These are registered at the API root, not under /users.

MethodEndpointBodyPurpose
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 ​

MiddlewareReadsNotes
userAuthMiddlewareuser_auth_tokenVerifies with JWT_SECRET
supplierAuthMiddlewaresupplier_auth_tokenVerifies with JWT_SECRET, then checks the supplier exists and is not suspended
adminMiddlewareadmin_auth_tokenVerifies with JWT_SECRET_ADMIN
authMiddlewareany auth cookieTries JWT_SECRET, then JWT_SECRET_ADMIN; also rejects suspended suppliers

Built with VitePress