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

M-K's avatar
Level 2

logout after session expire?

hi, maybe it's repeated question,

if I logout after the session expire I got 419 | Page Expired so how to redirect to the login page either as auto redirect or when i post the logout after session expire ,?

thanks,

0 likes
2 replies
Nakov's avatar

You can handle that manually, in your Exceptions\Handler.php class add this in the render method:

if ($exception instanceof TokenMismatchException) {
     return redirect('login')->with('message', 'An error message.');
}
Ehsan_Nosair's avatar

now im using laravel 9 and search for solution to this issue i found that the problem is VerifyCsrfToken middleware called before Authenticate middleware and if we just reorder the calling of this two middleware the issue will fixed so i just add this code to app/Http/Keernel.php

protected $middlewarePriority = [
    \App\Http\Middleware\Authenticate::class,
    \App\Http\Middleware\VerifyCsrfToken::class,
];

Please or to participate in this conversation.