One page application, all on Ajax, the problem arises that if the page is open for a long time and the token gets rotten and the user cannot understand what happened, because the javascript only to the console throws errors, and I don’t want to handle the problem everywhere. I tried to Ajax to periodically pull the server and request the current token. It seemed that the token had ceased to foul, the same token is returned if the server sees any requests from the current page. It is not clear how this token behaves in Laravel as a whole. The login page is not a pleasant situation - after 10-15 minutes of downtime - when trying to log in it complains that the token is rotten. Tell me where are the settings for managing the csrf token, and if not, then with what commands can you more finely manage this token?

    1 answer 1

    You can use the library Laravel Caffeine . It was created for this purpose,

    Library installation:

    composer require genealabs/laravel-caffeine 

    Then in config/app.php add the following to the providers :

     // 'providers' => [ GeneaLabs\LaravelCaffeine\Providers\LaravelCaffeineService::class, // ], 

    Then in /app/Http/Kernel.php add the following:

     // protected $middleware = [ \GeneaLabs\LaravelCaffeine\Http\Middleware\LaravelCaffeineDripMiddleware::class, // ]; 

    Just keep in mind that this option is for version 5.1 and 5.3, for 5.2 there is another guide, read more on the library page.