<?php

namespace App\Filters;

use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;

class AuthFilter implements FilterInterface
{
    public function before(RequestInterface $request, $arguments = null)
    {
        // Only protect transactions and admin routes
        $uri = service('uri');
        $segment1 = $uri->getSegment(1);
        
        if (in_array($segment1, ['transactions', 'admin'])) {
            if (!session()->get('isLoggedIn')) {
                return redirect()->to(site_url('auth/login'));
            }
        }
    }

    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
    {
        // Do nothing
    }
} 