Hey all!
I don't really know what happened but today I started up my dev environment to work on my extension that adds middleware and it just doesn't work anymore. I've isolated the problem to the __invoke method not being called for some reason. Here is the code I'm trying to use:
Event Handler:
class ConfigureMiddlewareListener
{
/**
* @var Dispatcher $events
*/
protected $events;
protected $logger;
protected $prefix = "Bearer ";
public function __construct()
{
$this->logger = new Logger("flarum_jwt_ext");
}
/**
* @param Dispatcher $events
*/
function listen(Dispatcher $events)
{
$this->logger->debug('listening to events');
$this->events = $events;
$events->listen(ConfigureMiddleware::class, [$this, 'handler']);
}
/**
* @param ConfigureMiddleware $event
*/
public function handler(ConfigureMiddleware $event)
{
$auth = new AuthenticateWithJWT();
$event->pipe($auth);
}
}
AuthenticateWithJWT.php
class AuthenticateWithJWT
{
protected $logger;
public function __construct()
{
$this->logger = new Logger('flarum-ext-jwt');
$this->logger->emergency('constructed');
}
public function __invoke(Request $request, Response $response, callable $out = null)
{
$this->logger->critical('invoked');
return $response->withStatus(500);
}
}
Any ideas? Nothing gets logged as an error. I see 'listening to events' and 'constructed' in the logs but that's it. It seems to only not invoke on API routes, but all responses for some reason come up as blank 200 responses regardless of it being an api request or not.