0
votes

I am trying to learn Laravel sanctum, I am stuck at the CSRF section, after changing the cors.php config value of 'supports_credentials' into true. I'm successfully getting a 204 response when connecting /sanctum/csrf-cookie. But after that when trying to connect to '/login', I am getting error 419 unknown status.

I have added this to my env file

SESSION_DOMAIN=localhost:8000 // Laravel backend
SANCTUM_STATEFUL_DOMAINS=http://127.0.0.1:3000 // React Fronend

Here is my Cors.php

'paths' => ['api/*', 'sanctum/csrf-cookie'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => true,

And here's my **React Code **

const handleSubmit = (e) => {
    e.preventDefault();

    apiClient.get("sanctum/csrf-cookie").then((response) => {
      apiClient
        .post(
          "api/login",{
            email: email,
            password: password,
          }).then((response) => {
              console.log(response);
           });
       });
  };

Below is apiClient's Code

import axios from "axios";

const apiClient = axios.create({
  baseURL: "http://127.0.0.1:8000/",
  withCredentials: true
});

export default apiClient;

API's are working completely fine on Postman

1
You try command. Php artisan optimize:clearMohammad Hasan
It magically works. But how?Hamza Afzal
Laravel make cacheMohammad Hasan

1 Answers

0
votes

You try command. Php artisan optimize:clear