Answer the question
In order to leave comments, you need to log in
Why is the 419 error beating?
Good day everyone!
Please help, I can't figure it out.
I have a 419 error when going to auth\[email protected]
Googling showed that the problem is in csrf and the session driver.
I make my own session driver (that's how it should be), but I can't figure out what I need to do to make everything work? What to return?
Here is the driver (in particular the write method):
class sessions implements SessionHandlerInterface {
public function write($sessionId, $data) {
$isSession = $this->read($sessionId) ? true : false;
if(!$isSession) {
$this->model->insert(['id' => $sessionId, 'payload' => serialize(base64_encode($data))]);
return true;
} else {
$x = $this->read($sessionId);
$payload = unserialize(base64_decode($x[0]['payload']));
return $payload['_token'];
// return true;
}
}
}
Route::post('/login', 'auth\[email protected]')->name('mylogin');
Route::get('/loginview', 'auth\[email protected]')->name('myloginget');
Route::group(['middleware' => ['custom']], function(){
Route::get('/sess', '[email protected]');
Route::get('/midd', '[email protected]')->name('midd');
Route::get('/filemanager', '[email protected]')->name('filemanager');
});
public function handle($request, Closure $next) {
if(Auth::check()) {
return $next($request);
} else {
return redirect()->route('myloginget');
}
}
Answer the question
In order to leave comments, you need to log in
In laravel 419, the absence of the csrf field in the request causes an error. The solution to the problem is in the official documentation . If you want to fix it, remove the middleware VerifyCsrfToken (not recommended) in App\Http\Kernel.php or add a csrf header.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question