Ocha API uses JSON Web Tokens (JWT) for authentication. When you register or log in, the API returns a signed token that is valid for 7 days. You include this token in theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/floriansalvi/HEIG-VD_Ocha-api/llms.txt
Use this file to discover all available pages before exploring further.
Authorization header of every request that requires authentication. There are no sessions or cookies — the token is the only credential the server recognises after login.
How tokens work
Tokens are signed withJWT_SECRET using the HS256 algorithm and embed the user’s id and role. The server verifies the token on every protected request without querying a session store. If the token is missing, invalid, or expired, the request is rejected with 401 Unauthorized.
Tokens expire exactly 7 days after they are issued. There is no refresh mechanism — you must log in again to obtain a new token.
Registering a user
Send aPOST request to /api/v1/auth with a JSON body containing email, password, and display_name. The phone field is optional.
201:
Field requirements
Password — must be at least 8 characters and include all of the following:- 1 uppercase letter
- 1 lowercase letter
- 1 number
- 1 special character
display_name — must be 3–30 characters, using only letters, numbers, and underscores. Must be unique across all accounts.
Logging in
Send aPOST request to /api/v1/auth/login with your email and password.
200:
Using the token
Include the token in every request to a protected endpoint using theAuthorization header with the Bearer scheme.
User roles
All accounts are assigned theuser role by default at registration. The admin role must be set directly in the database.
| Role | Access |
|---|---|
user | Read public resources, create orders, view own profile and order history |
admin | All user actions plus create/update/delete products and stores, view order statistics |
Understanding 401 vs 403
| Status | Meaning | Common cause |
|---|---|---|
401 Unauthorized | The request could not be authenticated | Token is missing, expired, or invalid |
403 Forbidden | The request was authenticated but the role is insufficient | A user tried to access an admin-only route |
401, obtain a fresh token by logging in. If you receive 403, the endpoint requires the admin role which cannot be self-assigned.