title: Axios POST to Laravel API results in 419 error but works fine in postman
body: <p>I have a new laravel project and im using Laravel sanctum api tokens to authenticate the api
  sending a post request with postman works fine
  but if i send it from my next.js project using Axios it give me a 419 error</p>
  <p>laravel project : localhost:8000</p>
  <p>next.js project : localhost:3000</p>
  <p>i think its a cors proplem but i dont realy know</p>
  <p>laravel cors.php</p>
  <pre><code>return [
  
  /*
  |--------------------------------------------------------------------------
  | Cross-Origin Resource Sharing (CORS) Configuration
  |--------------------------------------------------------------------------
  |
  | Here you may configure your settings for cross-origin resource sharing
  | or &quot;CORS&quot;. This determines what cross-origin operations may execute
  | in web browsers. You are free to adjust these settings as needed.
  |
  | To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
  |
  */
  
  'paths' =&gt; ['api/*', 'sanctum/csrf-cookie'],
  
  'allowed_methods' =&gt; ['*'],
  
  'allowed_origins' =&gt; ['*'],
  
  'allowed_origins_patterns' =&gt; [],
  
  'allowed_headers' =&gt; ['*'],
  
  'exposed_headers' =&gt; [],
  
  'max_age' =&gt; 0,
  
  'supports_credentials' =&gt; false,
    ];
  </code></pre>
  <p>Update</p>
  <p>api.js</p>
  <pre><code>import Axios from &quot;axios&quot;;
  
    let urls = {
    development: &quot;http://localhost:8000/api/&quot;,
    production: &quot;&quot;,
    };
    const api = Axios.create({
    baseURL: urls[process.env.NODE_ENV],
    headers: {
      Accept: &quot;application/json&quot;,
      &quot;Content-Type&quot;: &quot;application/json&quot;,
    },
    });
  
    export default api;
  </code></pre>
  <p>auth.js</p>
  <pre><code>import React, { createContext, useState, useContext, useEffect } from 
  
  &quot;react&quot;;
  import Cookies from &quot;js-cookie&quot;;
  import Router, { useRouter } from &quot;next/router&quot;;
  //api here is an axios instance
  import api from &quot;../services/Api&quot;;
  
  const AuthContext = createContext({});
  
  export const AuthProvider = ({ children }) =&gt; {
  
  
   const login = async (username, password) =&gt; {
      const { data: data } = await api.post(&quot;login&quot;, {
        username,
        password,
      });
  }
  
  }
  </code></pre>
  <p>Update
  i tried : <a href="https://stackoverflow.com/questions/46266553/why-does-the-laravel-api-return-a-419-status-code-on-post-and-put-methods">Why does the Laravel API return a 419 status code on POST and PUT methods?</a></p>
  <p>i have added the routes to the VerifyCsrfToken Middleware</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Middleware;
  
  use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
  
  class VerifyCsrfToken extends Middleware
  {
      /**
       * The URIs that should be excluded from CSRF verification.
       *
       * @var array
       */
      protected $except = [
          'http://localhost:8000/api/login'
          //
      ];
  }
  </code></pre>
  <p>same proplem i have tried commenting the Middleware same proplem</p>
  <pre><code>// \App\Http\Middleware\VerifyCsrfToken::class,
  </code></pre>
  <p>these are my routes</p>
  <p>api.php</p>
  <pre><code>Route::post('/login',[AuthController::class,'login']);
  
  
  Route::group(['middleware' =&gt; ['auth:sanctum']], function () {
  
  //test GRUD
  
     
  Route::get('/posts',[PostController::class,'index']);
  
  
  // logout 
  
  Route::post('/logout',[AuthController::class,'logout']);
  
  
  });
  </code></pre>
  <p>session.php i added this</p>
  <pre><code>  'domain' =&gt; 'localhost',
  </code></pre>
  <p>Note: im not using sanctum csrf-cookie im using sanctum api tokens and the routes im trying to access is not even protected</p>
  <p>Update
  <code>get, put</code> works fine the problem only with <code>post</code> request</p>