Every request to the Marbes API must prove identity through a signed JSON Web Token (JWT). The token carries the authenticated employee’s ID, name, role, and email. Roles are defined in the database and assigned to employees; the set of permissions a user has is resolved at runtime by querying theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/scoria02/marbes2021_backend/llms.txt
Use this file to discover all available pages before exploring further.
permisosbyuser endpoint. Two middleware functions—authMiddleware for standard endpoints and authOrSolicitudToken for public credit-application links—enforce authentication at the route level.
Authentication flow
Employee logs in
The client sends credentials (
email or name, plus password) to POST /api/auth/login. The server validates the credentials and returns a signed JWT.Token is attached to requests
The client includes the token in the
Authorization header of every subsequent request:authMiddleware validates the token
For protected routes,
authMiddleware extracts the token from the Authorization header, verifies it against JWT_SECRET, and attaches the decoded payload to req.user. If the token is missing, malformed, or expired, the request is rejected with 401.The user object on req.user
AfterauthMiddleware validates a token, it attaches the following object to the Express request:
The JWT payload is set at login time. If a role is reassigned after the token is issued, the change will not be reflected until the employee logs in again and receives a new token.
Role system
Roles are stored in the database and assigned to employees through the HR module. Each role has anombre (name), a descripcion, and an activo flag. An employee can hold multiple roles; each assignment records the fecha_asignacion and asignado_por (who granted it).
Managing roles
| Endpoint | Method | Description |
|---|---|---|
GET /api/rrhh/roles | GET | List all roles defined in the system |
POST /api/rrhh/roles | POST | Create a new role |
PUT /api/rrhh/user/roles/editar | PUT | Assign or update roles for an employee |
POST /api/rrhh/roles/permisos | POST | Assign permissions to a role |
GET /api/rrhh/roles/:rolNombre/analisis | GET | Inspect permissions assigned to a role |
Permissions
Permissions are assigned to roles, not to individual employees. To retrieve the resolved permissions for the currently authenticated user, call:req.user.id from the validated JWT and returns the set of permissions inherited through the employee’s assigned roles.
To list all permissions defined in the system:
Middleware reference
authMiddleware
Applied to all standard API endpoints. It:- Reads the
Authorizationheader and checks forBearer <token>format. - Verifies the JWT signature using the
JWT_SECRETenvironment variable. - Populates
req.userwith{ id, name, role, email }. - Calls
next()on success or responds401on failure.
authOrSolicitudToken
Used on endpoints that must be accessible both to authenticated employees and to external users following a one-time credit application link. It tries JWT authentication first; if that fails, it falls back to a solicitud link token.- The token exists in the
solicitudestable. - The
usado(used) flag isfalse. - The
expira_en(expiry) timestamp is in the future.
req.solicitudLink with { id, cliente_id, expira_en, usado } instead of req.user.
authOrSolicitudToken is currently applied to the economic activity catalog (GET /api/negocios/actividad_economica) and the countries catalog (GET /api/negocios/paises), which credit applicants need when filling in a credit application form.Error responses
| Condition | Status | Message |
|---|---|---|
No Authorization header | 401 | Acceso denegado. No se proveyó token. |
| Token fails JWT verification or expired | 401 | Token inválido o expirado. |
| Token structure is not an object | 401 | Token inválido: estructura incorrecta. |
| No JWT and no solicitud token provided | 401 | Se requiere autenticación (Bearer token) o token de solicitud (X-Solicitud-Token o campo token). |
| Solicitud token not found in DB | 401 | Token de solicitud no encontrado. |
| Solicitud token already used | 401 | Este link ya fue utilizado. |
| Solicitud token expired | 401 | El link ha expirado. |
Employee status values
An employee’sestatus field controls whether they can log in and operate in the system. The values are defined as strings in the database:
| Value | Meaning |
|---|---|
activo | Employee is active and can authenticate |
desactivo | Employee account is deactivated |
suspendido | Employee is temporarily suspended |
Login validation rules
The login endpoint accepts any one of the following identifiers alongsidepassword:
email— must be a valid email addressname— non-empty username stringcode— non-empty code string
400 with the message: Se requiere al menos un identificador: email, username o code.