25 / 01 / 12
You’ve worked with Laravel before, you’ve seen the 419 status code. This error happens when your CSRF token expires and you get a lovely "Page Expired" message. Not exactly the most user friendly experience right?
I remember the first time this happened to me. I was in the middle of a project, testing some forms and out of nowhere—bam! Page expired. No warning, no nice handling, just a stop to my workflow. I thought, "There’s gotta be a better way to handle this."
After some research I found out that while Laravel’s CSRF protection is good for security, the way it handles expired tokens could be better. I wanted a solution that would handle this error more nicely, maybe by redirecting the user back to the previous page with a new token, without too much disruption.
That’s when I decided to create a package for this. Introducing laravel-drunk-on-419 , this package catches 419 errors and redirects the user back to their previous location, so the experience is smoother when a CSRF token expires.
Install it via Composer:
composer require devtical/laravel-drunk-on-419
Once installed the package will automatically register the middleware in the web group to handle CSRF token expiry errors. So it will handle all requests in the web middleware group without you having to register it manually.
By using this package you can improve your application’s user experience by handling expired CSRF tokens more nicely, keep your users happy and your application secure.
Check out the GitHub repository for more info and to contribute. Let’s make Laravel development more user friendly, one package at a time!
Happy coding!