Php CSRF令牌不匹配,laravel和axios
我正在尝试为用户登录,但当我尝试登录时,出现错误Php CSRF令牌不匹配,laravel和axios,php,reactjs,laravel,axios,Php,Reactjs,Laravel,Axios,我正在尝试为用户登录,但当我尝试登录时,出现错误状态代码419。CSRF令牌不匹配。 我正在使用php artisan serve在上运行localhost 我想问题是我使用的是http而不是https,但我不确定(因为我知道php artisan Service只在http上工作) api.js Route::group(['middleware' => ['web']], function () { Route::post('register','Auth\RegisterContro
状态代码419。CSRF令牌不匹配。
我正在使用php artisan serve
在上运行localhost
我想问题是我使用的是http而不是https,但我不确定(因为我知道php artisan Service只在http上工作)
api.js
Route::group(['middleware' => ['web']], function () {
Route::post('register','Auth\RegisterController@register');
Route::post('login','Auth\LoginController@login');
});
登录控制器
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Auth;
use Illuminate\Http\Request;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
//protected $redirectTo = RouteServiceProvider::HOME;
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
有人知道如何纠正这个问题吗
谢谢你我能帮你
onSubmit(e){
e.preventDefault();
const {email , password} = this.state ;
axios.post('api/login', {
email,
password
})
.then(response=> {
this.setState({err: false,loggedIn:true,data:response.data.credentials.email},() => {
localStorage.setItem('allProjects', this.state.data), localStorage.setItem('loginVar', JSON.stringify(true))});
hashHistory.push("/") ;
})
.catch(error=> {
this.refs.email.value="";
this.refs.password.value="";
this.setState({err: true,loggedIn:false, errors: error.response.data,data:''});
console.log(error.response.data);
localStorage.setItem('allProjects', 'guest');
localStorage.setItem('loginVar', false);
});
}