> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/martin-ratti/PCFIX-Baru/llms.txt
> Use this file to discover all available pages before exploring further.

# Login

> Authenticate a user with email and password

## Endpoint

```
POST /api/auth/login
```

Authenticates a user using their email address and password. Returns a JWT token upon successful authentication.

## Request Body

<ParamField body="email" type="string" required>
  User's email address. Must be a valid email format.
</ParamField>

<ParamField body="password" type="string" required>
  User's password. Must be at least 1 character long.
</ParamField>

## Response

<ResponseField name="success" type="boolean">
  Indicates whether the request was successful.
</ResponseField>

<ResponseField name="data" type="object">
  Contains the authenticated user data and JWT token.

  <Expandable title="data properties">
    <ResponseField name="user" type="object">
      User object containing profile information.

      <Expandable title="user properties">
        <ResponseField name="id" type="number">
          Unique user identifier.
        </ResponseField>

        <ResponseField name="email" type="string">
          User's email address.
        </ResponseField>

        <ResponseField name="nombre" type="string">
          User's first name.
        </ResponseField>

        <ResponseField name="apellido" type="string">
          User's last name.
        </ResponseField>

        <ResponseField name="telefono" type="string" nullable>
          User's phone number (optional).
        </ResponseField>

        <ResponseField name="role" type="string">
          User's role (e.g., "USER", "ADMIN").
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="token" type="string">
      JWT authentication token valid for 7 days.
    </ResponseField>
  </Expandable>
</ResponseField>

## Status Codes

<ResponseField name="200" type="Success">
  Login successful. Returns user data and JWT token.
</ResponseField>

<ResponseField name="400" type="Bad Request">
  Invalid request body or validation error.
</ResponseField>

<ResponseField name="401" type="Unauthorized">
  Invalid credentials (incorrect email or password).
</ResponseField>

## Error Response

```json theme={null}
{
  "success": false,
  "error": "Credenciales inválidas"
}
```

## Example Request

```bash cURL theme={null}
curl -X POST https://api.pcfix.com/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "usuario@ejemplo.com",
    "password": "miPassword123"
  }'
```

```javascript JavaScript theme={null}
const response = await fetch('https://api.pcfix.com/api/auth/login', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    email: 'usuario@ejemplo.com',
    password: 'miPassword123'
  })
});

const data = await response.json();
console.log(data);
```

```python Python theme={null}
import requests

response = requests.post(
  'https://api.pcfix.com/api/auth/login',
  json={
    'email': 'usuario@ejemplo.com',
    'password': 'miPassword123'
  }
)

data = response.json()
print(data)
```

## Example Response

```json theme={null}
{
  "success": true,
  "data": {
    "user": {
      "id": 123,
      "email": "usuario@ejemplo.com",
      "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
