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
The user’s unique username
Response
Success message indicating login status
JWT authentication token valid for 4 hours
User information objectThe authenticated user’s username
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 -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
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"
}