Skip to main content
POST
/
api
/
auth
/
login
Login
curl --request POST \
  --url https://api.example.com/api/auth/login \
  --header 'Content-Type: application/json' \
  --data '
{
  "email": "<string>",
  "password": "<string>"
}
'
{
  "200": {},
  "400": {},
  "401": {},
  "success": true,
  "data": {
    "user": {
      "id": 123,
      "email": "<string>",
      "nombre": "<string>",
      "apellido": "<string>",
      "telefono": "<string>",
      "role": "<string>"
    },
    "token": "<string>"
  }
}

Endpoint

POST /api/auth/login
Authenticates a user using their email address and password. Returns a JWT token upon successful authentication.

Request Body

email
string
required
User’s email address. Must be a valid email format.
password
string
required
User’s password. Must be at least 1 character long.

Response

success
boolean
Indicates whether the request was successful.
data
object
Contains the authenticated user data and JWT token.

Status Codes

200
Success
Login successful. Returns user data and JWT token.
400
Bad Request
Invalid request body or validation error.
401
Unauthorized
Invalid credentials (incorrect email or password).

Error Response

{
  "success": false,
  "error": "Credenciales inválidas"
}

Example Request

cURL
curl -X POST https://api.pcfix.com/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "miPassword123"
  }'
JavaScript
const response = await fetch('https://api.pcfix.com/api/auth/login', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    email: '[email protected]',
    password: 'miPassword123'
  })
});

const data = await response.json();
console.log(data);
Python
import requests

response = requests.post(
  'https://api.pcfix.com/api/auth/login',
  json={
    'email': '[email protected]',
    'password': 'miPassword123'
  }
)

data = response.json()
print(data)

Example Response

{
  "success": true,
  "data": {
    "user": {
      "id": 123,
      "email": "[email protected]",
      "nombre": "Juan",
      "apellido": "Pérez",
      "telefono": "+1234567890",
      "role": "USER"
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  }
}

Notes

  • The JWT token is valid for 7 days from the time of issuance
  • Store the token securely and include it in the Authorization header for authenticated requests
  • Password validation requires at least 1 character, but the registration endpoint enforces a minimum of 6 characters

Build docs developers (and LLMs) love