Answer the question
In order to leave comments, you need to log in
How to solve Laravel TokenMismatchException issue?
The essence of the problem:
When sending an Ajax request with an expired csrf_token, an error is written to laravel.log.
Answer the question
In order to leave comments, you need to log in
And here is the solution:
You need to add a check in the "report" function and not in the "render" function in /app/Exceptions/Handler.php
The check itself:
if ($e instanceof \Illuminate\Session\TokenMismatchException) {
return response()->json(['msg'=> 'session expired', 'token'=> csrf_token()], 401);
}
The problem is that the first request is still with the wrong token.
If you want to solve your problem, you need to create a separate route, when accessed, a new token will be given. It can be made using the get method.
Well, on the frontend, by timer, request a new one and update
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question