I
I
ipokos2018-05-18 09:35:09
Laravel
ipokos, 2018-05-18 09:35:09

How to properly handle the ErrorException in VerifyCsrfToken error that appears if the form is open for a long time?

There is csrf_token() in the head, there is csrf_field() in the form, everything is ok, everything works.
The error occurs if you leave the form open for a while and then submit.
If I understand correctly, the error occurs because the token (header in the XSRF-TOKEN cookie) has already expired (its lifetime is 2h).
Where and how to process it correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
l4m3r, 2018-05-18
@ipokos

1) Well, for example, open App/Http/Middleware/VerifyCsrfToken.php and inherit handle.

public function handle($request, Closure $next)
    {
        try {
            return parent::handle($request, $next);
        } catch (TokenMismatchException $exception) {
            // ...
        }
    }

2) Catch in app/Exceptions/Handler.php in report(), using if ($exception instanceof TokenMismatchException)
3) just put more lifetime in session.php.

R
riot26, 2018-05-19
@riot26

https://github.com/GeneaLabs/laravel-caffeine

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question