# Authentication API Documentation

Base URL: `http://localhost:8000/api`

## 1. Register (Kayıt Ol)

Yeni bir kullanıcı kaydı oluşturur.

- **Endpoint**: `/register`
- **Method**: `POST`
- **Content-Type**: `application/json`

### Request Body

| Field | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| `name` | string | Yes | Kullanıcının adı. |
| `surname` | string | No | Kullanıcının soyadı. |
| `username` | string | Yes | Kullanıcı adı (Benzersiz olmalı). |
| `email` | string | Yes | E-posta adresi (Benzersiz olmalı). |
| `password` | string | Yes | Şifre (En az 8 karakter). |
| `password_confirmation`| string | Yes | Şifre tekrarı. |

### Success Response (201 Created)

```json
{
  "data": {
    "name": "Ahmet",
    "surname": "Yılmaz",
    "username": "ahmetyilmaz",
    "email": "ahmet@example.com",
    "updated_at": "2024-02-08T18:00:00.000000Z",
    "created_at": "2024-02-08T18:00:00.000000Z",
    "id": 1
  },
  "access_token": "1|laravel_sanctum_token_string...",
  "token_type": "Bearer"
}
```

### Error Response (422 Unprocessable Entity)

```json
{
    "message": "The given data was invalid.",
    "errors": {
        "email": [
            "The email has already been taken."
        ]
    }
}
```

---

## 2. Login (Giriş Yap)

Kullanıcı girişi yapar ve API token döner. Hem e-posta hem de kullanıcı adı ile giriş yapılabilir.

- **Endpoint**: `/login`
- **Method**: `POST`
- **Content-Type**: `application/json`

### Request Body

| Field | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| `login` | string | Yes | E-posta adresi VEYA Kullanıcı adı. |
| `password` | string | Yes | Şifre. |

### Success Response (200 OK)

```json
{
  "data": {
    "id": 1,
    "name": "Ahmet",
    "surname": "Yılmaz",
    "username": "ahmetyilmaz",
    "email": "ahmet@example.com",
    "email_verified_at": null,
    "created_at": "2024-02-08T18:00:00.000000Z",
    "updated_at": "2024-02-08T18:00:00.000000Z"
  },
  "access_token": "2|laravel_sanctum_token_string...",
  "token_type": "Bearer"
}
```

### Error Response (422 Unprocessable Entity - Invalid Credentials)

```json
{
    "message": "The given data was invalid.",
    "errors": {
        "login": [
            "Invalid credentials."
        ]
    }
}
```

---

## 3. Logout (Çıkış Yap)

Mevcut oturumu sonlandırır ve tokenı geçersiz kılar.

- **Endpoint**: `/logout`
- **Method**: `POST`
- **Headers**:
    - `Authorization`: `Bearer <access_token>`

### Success Response (200 OK)

```json
{
    "message": "Logged out successfully"
}
```

---

## 4. Get User (Kullanıcı Bilgisi)

Oturum açmış kullanıcının bilgilerini getirir.

- **Endpoint**: `/me`
- **Method**: `GET`
- **Headers**:
    - `Authorization`: `Bearer <access_token>`

### Success Response (200 OK)

```json
{
    "id": 1,
    "name": "Ahmet",
    "surname": "Yılmaz",
    "username": "ahmetyilmaz",
    "email": "ahmet@example.com",
    "email_verified_at": null,
    "created_at": "2024-02-08T18:00:00.000000Z",
    "updated_at": "2024-02-08T18:00:00.000000Z"
}
```
