statamic / ideas

💡Discussions on ideas and feature requests for Statamic
https://statamic.dev
30 stars 1 forks source link

Catch 419 errors after logging in #1189

Open robdekort opened 2 days ago

robdekort commented 2 days ago

There have been quite a few reports on Discord over the last weeks that on non expired browser windows, Laravel apps show the 419 error page after logging in. A retry fixes the issue. The 419 error page is not a pretty sight for clients. I feel it would be better if users would be redirected back to the login screen and get a retry warning there instead.

jasonvarga commented 1 day ago

You can do this already in your own apps for now in bootstrap/app.php (for Laravel 11)

return Application::configure(basePath: dirname(__DIR__))
    ->withExceptions(function (Exceptions $exceptions) {
+        $exceptions->render(function (\Symfony\Component\HttpKernel\Exception\HttpException $e) {
+            if ($e->getStatusCode() === 419) {
+                return redirect('/wherever-you-want-them-to-go');
+            }
+        });
    })->create();
robdekort commented 21 hours ago

Nice, thanks @jasonvarga!