<?php
/**
 * Authentication Middleware
 */

function auth_middleware(): void
{
    if (!SessionManager::isLoggedIn()) {
        set_error('Please log in to access this page.');
        redirect(APP_URL . '/login.php');
    }

    // Check if user is still active
    $user = current_user();
    if (!$user) {
        logout_user();
        set_error('Your account is no longer active.');
        redirect(APP_URL . '/login.php');
    }
}
