<?php
require_once '../../config/cors.php';
require_once '../../config/db.php';
require_once '../../helpers/response.php';

$headers = getallheaders();
$token = str_replace('Bearer ', '', $headers['Authorization'] ?? '');

if ($token) {
    try {
        // Delete token from database
        $stmt = $pdo->prepare("DELETE FROM user_tokens WHERE token = ?");
        $stmt->execute([$token]);
    } catch (PDOException $e) {
        // Token might not exist, that's fine
    }
}

sendSuccess(null, 'Logged out successfully');
?>