Php 例外情况:;Symfony\Component\HttpKernel\Exception\HttpException"&引用;CSRF令牌不匹配。”;419未知状态

Php 例外情况:;Symfony\Component\HttpKernel\Exception\HttpException"&引用;CSRF令牌不匹配。”;419未知状态,php,reactjs,laravel,Php,Reactjs,Laravel,我正在使用React上的laravel 8 Suncutumns SPA前端。 错误为不匹配令牌错误419未知状态 我很想解决这个问题 环境 CORS.php 'paths' => ['api/*', 'sanctum/csrf-cookie', 'login', 'register'], 'allowed_methods' => ['*'], 'allowed_origins' => ['*' , "localhost:3000"],

我正在使用React上的laravel 8 Suncutumns SPA前端。

错误为不匹配令牌错误419未知状态

我很想解决这个问题

环境

CORS.php

 'paths' => ['api/*', 'sanctum/csrf-cookie', 'login', 'register'],

    'allowed_methods' => ['*'],

    'allowed_origins' => ['*' , "localhost:3000"],

    'allowed_origins_patterns' => [],

    'allowed_headers' => ['*'],

    'exposed_headers' => [],

    'max_age' => 0,

    'supports_credentials' => true,
Web.php

Route::get('/', function () {
    return view('welcome');
});

Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
    return view('dashboard');
})->name('dashboard');
反应还原

 axios.defaults.withCredentials = true;
      apiClient.get('/sanctum/csrf-cookie').then(response => {
          console.log(response)
          apiClient.post('/login', {
              email: user.username,
              password: user.password
          }).then(response => {
              console.log(response)
              localStorage.setItem("loggedIn" , "true")
          }).catch(error => console.log(error))
      })
APIClient

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

提前感谢

laravel 8 Suncutumns SPA
基于代币或cookies的服务。?然后尝试
apiClient.post('/api/login',
而不是
/login
应该是
/api/login
这能回答你的问题吗?@KamleshPaul谢谢你的回复我正在使用sunctums使用web.php路径我正在跟随这个链接@billalsheikh检查他们提到的那篇文章
“将此添加到routes/api.php文件:”
normal
web.php
默认情况下具有csrf保护,因此您可以获得
419
error@KamleshPaul我正在Suncums中使用登录路由使用默认登录路由请检查此项
const baseURL = "http://localhost:8000";
const apiClient = axios.create({
    baseURL: baseURL,
    withCredentials: true
});