<?php
// ─── Savuki Drilling — POST /api/auth/logout.php ─────────────────────────

define('ROOT', dirname(__DIR__, 2));
require_once ROOT . '/core/DB.php';
require_once ROOT . '/core/Response.php';

header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, OPTIONS');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') exit;

$token = trim($_POST['token'] ?? $_GET['token'] ?? '');

if ($token) {
    $db = DB::get();
    $db->run("DELETE FROM api_tokens WHERE token = ?", [$token]);
}

Response::ok(null, 'Logged out successfully.');
