Use this file to discover all available pages before exploring further.
Ordervista authenticates API requests using JSON Web Tokens (JWT) following the Bearer scheme. When a user logs in, the server signs a token containing their identity and role, then returns it to the client. Every subsequent request to a protected endpoint must include that token in the Authorization header. The verifyToken middleware validates the signature against the JWT_SECRET environment variable, and the authorizeRoles middleware checks the id_rol claim to enforce per-endpoint permissions.
Call POST /api/auth/register to create a new user account. New accounts are always assigned the Customer role (id_rol: 3). The nombre, apellido, email, and password fields are required; telefono is optional.
Call POST /api/auth/login with a valid email and password. The server looks up the account by email, verifies the submitted password against the stored bcrypt hash, and — on success — returns a signed JWT alongside the authenticated user’s profile.
Never embed tokens directly in source code or commit them to version control. Store them in environment variables on the server side, or in localStorage / a secure cookie on the client side.
Each token is signed with jwt.sign() using HS256 and contains the following claims:
Claim
Type
Description
id_usuario
number
Unique identifier of the authenticated user
email
string
User’s email address
id_rol
number
Role ID used by authorizeRoles to gate endpoint access
exp
number
Unix timestamp at which the token expires (2 hours from issue)
The id_rol claim maps to the three system roles:
id_rol
Role
1
Admin
2
Operator
3
Customer
You can inspect a token’s claims without a library by decoding the Base64 middle segment, or use any JWT debugger. The signature itself is verified server-side only.
The verifyToken and authorizeRoles middleware return the following errors when authentication or authorisation fails:
HTTP Status
mensaje
Cause
401
"Token no proporcionado"
Authorization header is absent
401
"Token inválido o expirado"
Signature verification failed or token has expired
401
"Usuario no autenticado"
req.user was not set before authorizeRoles ran
403
"No tiene permisos para acceder a este recurso"
Token is valid but id_rol is not in the allowed roles for this endpoint
A 403 response means your credentials are valid but your role does not permit the action. Logging in with a different account that holds the correct role is the only remedy — do not retry the same request expecting a different outcome.
Tokens are valid for 2 hours from the moment they are issued (configured as expiresIn: "2h" in generateToken.js). After expiry, any request carrying that token returns:
{ "mensaje": "Token inválido o expirado"}
When this occurs, re-authenticate by calling POST /api/auth/login again to receive a fresh token. There is no refresh-token mechanism — a full login is required.
Call POST /api/auth/logout to signal the end of a session:
curl -X POST https://ordervista-backend.onrender.com/api/auth/logout \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
Response — 200 OK
{ "mensaje": "Sesión cerrada correctamente"}
Because JWTs are stateless, the server does not maintain a token denylist. Token invalidation is handled client-side: upon receiving a successful logout response, remove the token from localStorage (or whichever client storage mechanism you use) so it cannot be reused.
If a token is stolen before it expires, there is currently no server-side mechanism to revoke it. Keep tokens short-lived, transmit them only over HTTPS, and clear them immediately on logout.