Skip to main content

POST /login

Authenticates a user with username and password credentials and returns a JWT token for subsequent API requests.
This is a public endpoint and does not require authentication.

Request Body

username
string
required
The user’s unique username
password
string
required
The user’s password

Response

message
string
Success message indicating login status
token
string
JWT authentication token valid for 4 hours
user
object
User information object
user.username
string
The authenticated user’s username
user.role
string
The user’s role (e.g., “vendedor”)
The JWT token expires after 4 hours. Make sure to handle token refresh or re-authentication in your application.

Example Request

cURL
curl -X POST http://localhost:3000/login \
  -H "Content-Type: application/json" \
  -d '{
    "username": "john_doe",
    "password": "secure_password123"
  }'

Example Response

{
  "message": "Login exitoso",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "username": "john_doe",
    "role": "vendedor"
  }
}

Error Responses

401 Unauthorized
User not found
{
  "message": "Usuario no encontrado"
}
Incorrect password
{
  "message": "Contraseña incorrecta"
}
500 Internal Server Error
{
  "message": "Error en el login",
  "error": "Error details"
}

Build docs developers (and LLMs) love