A
A
Apostol632020-02-28 10:02:12
Laravel
Apostol63, 2020-02-28 10:02:12

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;
        }
    }
}


Here are the routes:
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');
});


Here is my middleware:
public function handle($request, Closure $next) {
        if(Auth::check()) {
            return $next($request);
        } else {
            return redirect()->route('myloginget');
        }
    }


I can't quite figure out what I'm missing.

PS
Please do not throw stones

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Popov, 2020-02-28
@be_a_dancer

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 question

Ask a Question

731 491 924 answers to any question