title: How to getAttribute from middleware in slim
body: <p>I have a problem when I try to get an attribute set in a previous middleware in Slim 4.</p>
  
  <p>I use middlewares in app/middleware.php<br>
  I use JwtAuthentication middleware to check a token and I want to pass the decoded token to the next middleware : CheckTokenInDatabaseMiddleware.</p>
  
  <p>I returned the $request with the decoded token : <code>return $response-&gt;withAttribute("decoded", $arguments['decoded']);</code></p>
  
  <p>In CheckTokenInDatabaseMiddleware the $request->getAttribute('decoded') returns NULL</p>
  
  <p>I have a slim-skeleton and use this :  </p>
  
  <p><strong>app/middleware.php</strong></p>
  
  <pre><code>declare(strict_types=1);
  
  use App\Application\Middleware\CheckTokenInDatabaseMiddleware;
  use App\Application\Middleware\SessionMiddleware;
  use Psr\Http\Message\ResponseInterface as Response;
  use Psr\Http\Message\ServerRequestInterface as Request;
  use Slim\App;
  use Tuupola\Middleware\JwtAuthentication;
  
  return function (App $app) {
      $app-&gt;add(SessionMiddleware::class);
      $app-&gt;add(new JwtAuthentication([
          "ignore" =&gt; ['/auth/signin', '/auth/signout'],
          'path' =&gt; ['/auth/me'],
          'secret' =&gt; getenv('JWT_SECRET'),
          "before" =&gt; function (Request $request, $arguments) {
              return $request-&gt;withAttribute("decoded", $arguments["decoded"]);
          }
      ]));
      $app-&gt;add(CheckTokenInDatabaseMiddleware::class);
  };
  </code></pre>
  
  <p><strong>app/Application/Middleware/CheckTokenInDatabaseMiddleware.php</strong></p>
  
  <pre><code>declare(strict_types=1);
  
  namespace App\Application\Middleware;
  
  use App\Domain\User\UserRepository;
  use Psr\Http\Message\ResponseInterface as Response;
  use Psr\Http\Message\ServerRequestInterface as Request;
  use Psr\Http\Server\MiddlewareInterface as Middleware;
  use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
  
  class CheckTokenInDatabaseMiddleware implements Middleware
  {
      protected $userRepository;
  
      /**
       * {@inheritdoc}
       */
      public function process(Request $request, RequestHandler $handler): Response
      {
          $token = $request-&gt;getAttribute('decoded');
  
          var_dump($token); // returns NULL
          die();
  
          return $handler-&gt;handle($request);
      }
  
      public function __construct(UserRepository $userRepository)
      {
          $this-&gt;userRepository = $userRepository;
      }
  }
  </code></pre>