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

Johny22's avatar

Handling 419 Page Expired Errors on Session Expiry

If a user's session expires and they attempt to log out, the application throws a 419 Page Expired error. I would like the application to redirect the user to the login page in this case, rather than displaying the error. How can I catch this 419 error and implement a custom redirect?

0 likes
3 replies
tykus's avatar

You could catch and handle the TokenMismatchException exception in bootstrap/app.php

use Illuminate\Session\TokenMismatchException;
// ...
->withExceptions(function (Exceptions $exceptions) {
    $exceptions->render(function (TokenMismatchException $e, Request $request) {
        return redirect()->route('login');
    });
})

However, this is blunt... every 419 is going to be redirected to login.

Please or to participate in this conversation.