<?php
require_once __DIR__ . '/includes/config.php';
start_session();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    csrf_check_or_die();
    $uid = $_SESSION['uid'] ?? null;
    if ($uid) {
        audit_log('user.logout', 'user', (int) $uid, userId: (int) $uid);
    }
    logout();
    flash('success', 'You have been signed out.');
}
redirect('/login.php');
