<?php
namespace App\Middlewares;

class AuthMiddleware {
    
    public function handle() {
        if (!isset($_SESSION['user_id'])) {
            header('Location: /nis-migrant-ereg/login');
            exit;
        }
        
        // Check session expiry
        if (isset($_SESSION['last_activity']) && (time() - $_SESSION['last_activity'] > SESSION_LIFETIME)) {
            session_unset();
            session_destroy();
            header('Location: /nis-migrant-ereg/login?expired=1');
            exit;
        }
        
        $_SESSION['last_activity'] = time();
    }
}