Skip to main content
Authenticates a user with username and password, returning a JWT token for subsequent API requests.

Endpoint

POST /auth/login

Authentication

This endpoint does not require authentication (it’s used to obtain the token).

Request Body

nomUsuario
string
required
Username for authentication
contrasena
string
required
User password

Response

access_token
string
JWT token to use for authenticated requests
user
object
User information

Example Request

curl -X POST http://localhost:3000/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "nomUsuario": "admin",
    "contrasena": "admin123"
  }'

Example Response

{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": 1,
    "nombre": "Administrator",
    "nomUsuario": "admin",
    "rol": "Admin"
  }
}

Error Responses

Invalid Credentials

{
  "statusCode": 401,
  "message": "Invalid credentials"
}

Validation Error

{
  "statusCode": 400,
  "message": [
    "nomUsuario should not be empty",
    "contrasena should not be empty"
  ],
  "error": "Bad Request"
}
Store the access_token securely and include it in the Authorization header for subsequent requests: Authorization: Bearer {access_token}

Build docs developers (and LLMs) love