<?php
session_start();

header("Access-Control-Allow-Origin: https://enerliths.com");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Headers: Content-Type");
header("Access-Control-Allow-Methods: POST, OPTIONS");
header("Content-Type: application/json");

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(200);
    exit();
}

require "../config/db.php";

$user_id = $_SESSION["user_id"];

$stmt = $conn->prepare("SELECT enabled FROM user_2fa WHERE user_id=?");
$stmt->bind_param("i",$user_id);
$stmt->execute();

$result = $stmt->get_result()->fetch_assoc();

if($result && $result["enabled"]==1){
    echo json_encode(["enabled"=>true]);
}else{
    echo json_encode(["enabled"=>false]);
}