# Authentication API Documentation

## Register

**Endpoint:** `POST /api/auth/register/`

**Request:**
```json
{
  "username": "testuser",
  "email": "test@example.com",
  "password": "SecurePass123!",
  "password2": "SecurePass123!",
  "phone": "+9647701234567" // Optional
}
```

**Response (201):**
```json
{
  "user": {
    "id": 1,
    "username": "testuser",
    "email": "test@example.com",
    "role": "user"
  },
  "access": "eyJ0eXAiOiJKV1QiLCJhbG...",
  "refresh": "eyJ0eXAiOiJKV1QiLCJhbG..."
}
```

## Login

**Endpoint:** `POST /api/auth/login/`

**يمكنك تسجيل الدخول باستخدام:**
- اسم المستخدم (username)
- البريد الإلكتروني (email)

**Request:**
```json
{
  "username": "testuser OR test@example.com",
  "password": "SecurePass123!"
}
```

**Response (200):**
```json
{
  "user": {
    "id": 1,
    "username": "testuser",
    "email": "test@example.com"
  },
  "access": "eyJ0eXAiOiJKV1QiLCJhbG...",
  "refresh": "eyJ0eXAiOiJKV1QiLCJhbG..."
}
```

**Error Responses:**
- `400` - Missing fields: `{"error": "اسم المستخدم أو البريد الإلكتروني وكلمة المرور مطلوبة"}`
- `401` - Invalid credentials: `{"error": "اسم المستخدم أو البريد الإلكتروني أو كلمة المرور غير صحيحة"}`
- `401` - Account disabled: `{"error": "حساب المستخدم معطل"}`

## Token Refresh

**Endpoint:** `POST /api/auth/token/refresh/`

**Request:**
```json
{
  "refresh": "eyJ0eXAiOiJKV1QiLCJhbG..."
}
```

**Response (200):**
```json
{
  "access": "eyJ0eXAiOiJKV1QiLCJhbG..."
}
```

## Logout

**Endpoint:** `POST /api/auth/logout/`

**Headers:**
```
Authorization: Bearer <access_token>
```

**Request:**
```json
{
  "refresh": "eyJ0eXAiOiJKV1QiLCJhbG..."
}
```

**Response (200):**
```json
{
  "message": "Successfully logged out"
}
```

