POS Authentication
The POS Authentication API enables secure user authentication for Point of Sale systems using database credentials. Authentication is performed by verifying user credentials against the PostgreSQL database roles, and successful authentication returns a JWT token for subsequent authorized requests.Endpoints Overview
| Method | Endpoint | Authentication | Description |
|---|---|---|---|
| POST | /api/pos/auth/login | None | Authenticate user and receive JWT token |
| GET | /api/pos/auth/access | Required | Get user’s role-based access permissions |
POST /api/pos/auth/login
Authenticates a POS user using their database credentials. The endpoint attempts to establish a database connection with the provided credentials, retrieves the user’s role from PostgreSQL roles, and generates a JWT token upon successful authentication.Request
The database username for authentication
The database password for authentication
Response
Status message indicating login success
JWT token for authenticated requests. Contains user credentials and role information.
The PostgreSQL role name assigned to the authenticated user
Example Request
Response Examples
Success Response (200 OK)
Success Response (200 OK)
Bad Request (400)
Bad Request (400)
This error occurs when either
user or password fields are missing from the request body.Unauthorized (401)
Unauthorized (401)
Implementation Details
The login endpoint uses PostgreSQL role-based authentication. It queries the
pg_roles and pg_auth_members system tables to determine the user’s role membership after successful authentication.usuario: The authenticated usernamepassword: The user’s password (encrypted in token)role: The PostgreSQL role name- Expiration time configured via
JWT_EXPIRES_INenvironment variable
GET /api/pos/auth/access
Retrieves the role-based access permissions for the authenticated user. This endpoint requires a valid JWT token and returns a permission matrix indicating which modules the user can access.This endpoint requires authentication. Include the JWT token in the Authorization header.
Authentication
Bearer token received from the login endpointExample:
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...Response
The user’s role name
Object containing boolean flags for each module permission
Example Request
Response Examples
Sales Role (adm_ventas)
Sales Role (adm_ventas)
Warehouse Role (adm_bodega)
Warehouse Role (adm_bodega)
Purchasing Role (adm_compras)
Purchasing Role (adm_compras)
Admin Role (admin/postgres)
Admin Role (admin/postgres)
Unauthorized (401)
Unauthorized (401)
Role Permissions Matrix
The following table shows the default access permissions for each role:| Role | Producto | Materia Prima | Cliente | Proveedor | Estándar | Factura | Orden Compra | Bodega |
|---|---|---|---|---|---|---|---|---|
| bodega / adm_bodega | ✓ | ✓ | ✗ | ✗ | ✓ | ✗ | ✗ | ✓ |
| ventas / adm_ventas / adm_fact | ✓ | ✗ | ✓ | ✗ | ✗ | ✓ | ✗ | ✗ |
| compras / adm_compras | ✗ | ✓ | ✗ | ✓ | ✗ | ✗ | ✓ | ✗ |
| admin / postgres | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| default | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ |
Error Codes
| Status Code | Description |
|---|---|
| 200 | Request successful |
| 400 | Bad request - missing required fields |
| 401 | Unauthorized - invalid credentials or token |
| 500 | Internal server error |