Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sebastian.virlan's avatar

TokenMismatchException sometimes for ajax call with Remember Me checked

Hi, I have a datatable integrated on my page which get data through ajax. The login system is based on Laravel Auth.

Initially I was logging on the website without checking the Remember Me option and the ajax calls was successful every time, but when I decided to Remember the Password and navigate to the page with the datatable I realized that 1 of 5 refresh on page will fail to get data through ajax.

What could cause this? Why is so random? And why only when I hit Remember Me? Also when sometimes I log in and log out and log in again I get TokenMismatchException directly after login.

0 likes
3 replies
shanely's avatar

put it here inside your web middleware

Route::group(['middleware' => 'web'], function () {
     //your route here
});
sebastian.virlan's avatar

Did not solved my issue, the only difference now is when the TokenMismatchException occure it redirects me to the login page (so it destroy the session).

What I noticed is that on MIcrosoft Edge and Firefox I am not encountering the issue.

Also when the error occure I don't have a response header with the CSRF code.

natcave's avatar

I'm having the same issue. Any update?

Please or to participate in this conversation.