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

kriolo_developer's avatar

TokenMismatchException on Login Page or During Logout

Hi Guys,

So I have this problem: Whenever I spend too much time away from my application and then return to it and try to do something, let's say, perform the logout, I just get a TokenMismatchException.

This also happens whenever I leave my application on the login page for a long time and then return to it and try to perform the Login.

I know this is because of how Laravel handles Sessions, but I would rather have my users NOT seeing an error page like the TokenMismatchException one. Is there a way around this? Like maybe automatically redirecting the user to a "lockscreen" whenever they spend too much time away from the application. And another way around for the login case as well.

Thank You

0 likes
1 reply
Cronix's avatar

I think the easiest solution is to use this package, which pings your app every x minutes (which keeps the session from timing out). Just make sure the time is set for less than your session. Like my session is 2 hours, so I have it ping once/hour. It's very lightweight and simple to use.

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

Please or to participate in this conversation.