By default, Laravel Sanctum token authentication will either completely block access to protected routes or allow it at the expense of not being able to detect if the user is logged in. However, there are valid scenarios whereby a route should be accessible to guests and at the same time allow bearer token authentication. One of the many ways to achieve this is by changing the default guard assigned to the /api route group.
I needed to add reCAPTCHA v2 to a couple of forms and most of the results on Google pointed to these large Composer packages that were simply too much.
This article will cover how to do create a new Laravel Middleware to validate reCAPTCHA v2 requests with just a few lines of code.
Time to read, implement, QA and deploy to production: 3.141592 minutes.
By default Fractal has native support for Laravel: