Login flow
Send aPOST request to /api/auth/login with your username and password. The API validates the credentials against the database (passwords are hashed with bcrypt), and returns a signed JWT along with basic user information.
Request
POST /api/auth/login
The user’s login handle. Must be between 3 and 30 characters.
The user’s password. Must be at least 6 characters.
Response
access_token — you’ll need it for every protected endpoint.
Using the token
Include the token in theAuthorization header as a Bearer token on all subsequent requests:
Tokens are extracted from the
Authorization: Bearer <token> header only. The API does not support cookie-based or query-parameter authentication.Profile endpoint
GET /api/auth/profile returns the currently authenticated user’s information. This is useful for confirming that a token is still valid and for retrieving the user’s role.
Roles
The API enforces two roles:| Role | Access level |
|---|---|
admin | Full access to all endpoints, including administrative operations |
cajero | Operational access for point-of-sale tasks |
rol claim) and verified on each request by the JwtStrategy. The RolesGuard then checks whether the authenticated user’s role matches the roles required by a given endpoint.
Protecting endpoints with roles
In the NestJS codebase, endpoints are protected by combiningAuthGuard('jwt') with RolesGuard and the @Roles() decorator:
@Roles():
Error responses
401 Unauthorized
Returned when authentication fails — either no token was provided, the token is malformed, or the token has expired.- Missing
Authorizationheader - Expired JWT
- Invalid signature (e.g. wrong
JWT_SECRET) - Credentials are incorrect on login
403 Forbidden
Returned when the token is valid but the user’s role does not satisfy the@Roles() requirement on the endpoint.
A
403 means the user is authenticated but not authorized. A 401 means the user could not be authenticated at all. If you are receiving a 403 unexpectedly, verify that the rol field in your JWT payload matches the role expected by the endpoint.