title: Slim jwt token(sent by axios request) not found
body: <p>I'm setting up a Vue js/Vuetify website with a <a href="http://www.slimframework.com/" rel="nofollow noreferrer">PHP Slim Framework</a> API, and <a href="https://github.com/tuupola/slim-jwt-auth" rel="nofollow noreferrer">tuuopla slim-jwt-auth</a> as a middleware for JWT token authentication.
  The unprotected routes are working fine but when I try to send axios requests to the protected routes in the API I only got token not found error.</p>
  
  <p>I dont know if the problem is at Vue js, axios or the API configuration. <code>curl</code> and Postman gives the decoded key as expected when acessing the protected route, only the Vue js website gives this errors.
  To run the API I'm using PHP built-in server: `php -S localhost:8000 -t public/</p>
  
  <p>In any case, the <code>localStorage.getItem("token")</code> does exist, as I tried to print them before every request as well in the interceptor.</p>
  
  <p>Here is a test component :</p>
  
  <pre><code>&lt;template&gt;
   &lt;v-btn @click="test"&gt;Test&lt;/v-btn&gt;
   &lt;v-btn @click="test2"&gt;Test&lt;/v-btn&gt;
  &lt;/template&gt;
  &lt;script&gt;
    methods: {
      test() {
        axios
          .post("api/user",{},{
              headers: {
                Authorization: `Bearer ${localStorage.getItem("token")}`
              }
            }
          )
          .then(res =&gt; console.log(res))
          .catch(err =&gt; console.log(err));
      },
      test2() {
        var yourConfig = {
          headers: {
            Authorization: "Bearer " + localStorage.getItem("token")
          }
        };
        axios
          .get("test", yourConfig)
          .then(res =&gt; console.log(res))
          .catch(err =&gt; console.log(err));
      }
    },
  &lt;/script&gt;
  </code></pre>
  
  <p>axios config(tried with and without the interceptor)</p>
  
  <pre><code>axios.defaults.baseURL = "http://localhost:8000";
  axios.interceptors.request.use(
    config =&gt; {
      let token = localStorage.getItem("token");
  
      if (token) {
        config.headers["Authorization"] = `Bearer ${token}`;
      }
      console.log(token)
      return config;
    },
  
    error =&gt; {
      return Promise.reject(error);
    }
  );
  </code></pre>
  
  <p>Slim <code>index.php</code>(a protected and a unprotected sample routes for my tests)</p>
  
  <pre><code>...
  use Slim\Http\Request;
  use Slim\Http\Response;
  
  $app-&gt;group('/api', function (\Slim\App $app) {
      $app-&gt;get('/user', function (Request $request, Response $response, array $args) {
          return $response-&gt;withJson($request-&gt;getAttribute('decoded_token_data'));
      });
  });
  $app-&gt;get('/test', function (Request $request, Response $response, array $args) {
      return $response-&gt;withJson(["hi"=&gt;"hello"]);
  });
  
  // Run app
  $app-&gt;run();
  </code></pre>
  
  <p><code>middleware.php</code>(tried many configurations)</p>
  
  <pre><code>&lt;?php
  // Application middleware
  use Slim\Http\Request;
  use Slim\Http\Response;
  
  use Monolog\Logger;
  use Monolog\Handler\RotatingFileHandler;
  
  
  $logger = new Logger("slim");
  $rotating = new RotatingFileHandler(__DIR__ . "/logs/slim.log", 0, Logger::DEBUG);
  $logger-&gt;pushHandler($rotating);
  
  $app-&gt;add(new \Tuupola\Middleware\JwtAuthentication([
      "secure" =&gt; false,
      "logger" =&gt; $logger,
      "relaxed" =&gt; ["localhost:8080"],
      "attribute" =&gt; "decoded_token_data",
      "secret" =&gt; "mykey",
      "algorithm" =&gt; ["HS256"],
      "rules" =&gt; [
          new \Tuupola\Middleware\JwtAuthentication\RequestPathRule([
              // Degenerate access to '/api'
              "path" =&gt; ["/api"],
              // It allows access to 'login' without a token
              "passthrough" =&gt; [
                  "/login_admin"
                  //"/login_admin"
              ]
          ])
      ],
      "error" =&gt; function ($response, $arguments) {
          $data["status"] = "error";
          $data["message"] = $arguments["message"];
          return $response
              -&gt;withHeader("Content-Type", "application/json")
              -&gt;write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
      }
  ]));
  </code></pre>
  
  <p>The errors when tried to access the <code>api/user</code> route:</p>
  
  <ul>
  <li>Chrome console:</li>
  </ul>
  
  <pre><code>OPTIONS http://localhost:8000/api/user net::ERR_ABORTED 401 (Unauthorized)
  Access to XMLHttpRequest at 'http://localhost:8000/api/user' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
  </code></pre>
  
  <ul>
  <li>API Response:</li>
  </ul>
  
  <pre><code>{
      "status": "error",
      "message": "Token not found."
  }
  </code></pre>