# Login (POST)

Autenticati con email e password per ottenere un token JWT.

## Endpoint

```
POST https://api.pocketalert.app/v1/auth/signin
```

## Richiesta

### Header

| Header | Obbligatorio | Descrizione |
|--------|:--------:|-------------|
| `Content-Type` | ✅ | `application/json` |

### Parametri del body

| Parametro | Tipo | Obbligatorio | Descrizione |
|-----------|------|:--------:|-------------|
| `email` | string | ✅ | Il tuo indirizzo email registrato |
| `password` | string | ✅ | La password del tuo account |

### Esempio di richiesta

**cURL**

```bash
curl -X POST "https://api.pocketalert.app/v1/auth/signin" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "your-password"
  }'
```

**JavaScript**

```javascript
const response = await fetch('https://api.pocketalert.app/v1/auth/signin', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    email: 'user@example.com',
    password: 'your-password'
  })
});

const { token } = await response.json();
// Use token in Authorization header for subsequent requests
```

**Python**

```python
import requests

response = requests.post(
    'https://api.pocketalert.app/v1/auth/signin',
    json={
        'email': 'user@example.com',
        'password': 'your-password'
    }
)

data = response.json()
# Use token in Authorization header for subsequent requests
```

**PHP**

```php
$response = Http::post('https://api.pocketalert.app/v1/auth/signin', [
    'email' => 'user@example.com',
    'password' => 'your-password',
]);

$token = $response->json()['token'];
// Use token in Authorization header for subsequent requests
```

## Risposta

### Risposta di successo

> **Tip: 200 OK**
>
> Autenticazione riuscita

| Campo | Tipo | Descrizione |
|-------|------|-------------|
| `token` | string | Token JWT per l'autenticazione API |
| `email` | string | Indirizzo email dell'utente |
| `name` | string | Nome visualizzato dell'utente |
| `avatar` | string | URL dell'immagine avatar dell'utente |

```json
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "email": "user@example.com",
  "name": "John Doe",
  "avatar": ""
}
```

### Uso del token

Dopo aver ottenuto il token, includilo nelle richieste successive:

```bash
curl -X GET "https://api.pocketalert.app/v1/messages" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
```

### Risposte di errore

| Stato | Descrizione |
|:------:|-------------|
| `400` | Richiesta non valida — email o password mancanti, o captcha non superato |
| `401` | Credenziali non valide — password errata o email sconosciuta |

> **Tip: Consiglio**
>
> Per le integrazioni lato server, ti consigliamo di usare le [chiavi API](https://pocketalert.app/account/apikeys) al posto dei token JWT. Le chiavi API non scadono e sono più semplici da gestire.
