<?php
require_once __DIR__ . '/../auth_middleware.php'; // JWT doğrulaması (sub user id’sini ayarlar)
require_once '/home/akgbilis/fi_sf/config.php';

header('Content-Type: application/json');

// Kullanıcı id'si JWT’den alınır
$userId = $decoded->sub ?? null;

if (!$userId) {
    http_response_code(401);
    echo json_encode([
        "success" => false,
        "message" => "Unauthorized"
    ]);
    exit;
}

// Nickname’i çek
$stmt = $pdo->prepare("SELECT nickname FROM users WHERE id = ?");
$stmt->execute([$userId]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);

if ($user && !empty($user["nickname"])) {
    echo json_encode([
        "success" => true,
        "user" => [
            "nickname" => $user["nickname"]
        ]
    ]);
} else {
    http_response_code(404);
    echo json_encode([
        "success" => false,
        "message" => "User or nickname not found"
    ]);
}