<?php
class AuthMiddleware
{
    public function handle(Request $request): void
    {
        if (!Auth::check()) {
            if ($request->isAjax()) {
                Response::json(['success' => false, 'message' => 'Unauthorized'], 401);
            }
            Session::flash('redirect_after_login', $request->uri());
            Response::redirect('/login');
        }
    }
}