title: Laravel Sanctum - sanctum/csrf-cookie (204 "No content")
body: <p>Laravel sanctum has been a bit of a headache for me as i have spent hours trying to figure out why <code>sanctum/csrf-cookie</code> route returns no content. initially the same route return 404 not found but after adding <code>'prefix' =&gt; 'api/sanctum'</code> <strong>config/sanctum.php</strong> it seems to work except that it outputs nothing and no cookie is set in my browser.</p>
  <p><strong>Here are some of my codes</strong></p>
  <p><strong>.env</strong></p>
  <pre><code>SANCTUM_STATEFUL_DOMAINS=localhost:8080
  SPA_URL=http://localhost:8080
  SESSION_DOMAIN=localhost
  </code></pre>
  <p><strong>--config/cors.php</strong></p>
  <pre class="lang-php prettyprint-override"><code>'paths' =&gt; [
          'api/*',
          'login',
          'logout',
          'register',
          'user/password',
          'forgot-password',
          'reset-password',
          'sanctum/csrf-cookie',
          'user/profile-information',
          'email/verification-notification',
        ],
  
      'allowed_methods' =&gt; ['*'],
  
      'allowed_origins' =&gt; ['*'],
  
      'allowed_origins_patterns' =&gt; [],
  
      'allowed_headers' =&gt; ['*'],
  
      'exposed_headers' =&gt; [],
  
      'max_age' =&gt; 0,
  
      'supports_credentials' =&gt; true,
  </code></pre>
  <p><strong>axios</strong></p>
  <pre class="lang-js prettyprint-override"><code>export const authClient = axios.create({
    baseURL: process.env.VUE_APP_API_URL,
    withCredentials: true, // required to handle the CSRF token
  });
  </code></pre>
  <p>and having done all of that, if i tried to generate a token using</p>
  <pre class="lang-js prettyprint-override"><code>axios.get('/sanctum/csrf-cookie').then(response =&gt; {
      // Login...
  });
  </code></pre>
  <p>i get <code>204 no content</code> response
  i have also added the api middleware in kernel.php as instructed in the <a href="https://laravel.com/docs/8.x/sanctum#spa-authentication" rel="nofollow noreferrer">doucmentation </a> but still wont set the cookie. and when i try to make request to another route protected by sanctum i <code>419 token mismatch</code>.
  i have also run a fresh installation of laravel, <code>php artisan optimize</code>, cleared my brower history, checked the endpoints in postman but still thesame <code>204 and 419</code> exceptions</p>