For anyone who are interested in an answer: I found a solution to the CSRF 419 error with a workaround! Instead of using the .test domain (http://react-backend.test), I downloaded PHP and started the Laravel backend using a PHP server at 127.0.0.1:8081. This allowed me to serve the backend locally without the .test domain, which resolved the CSRF validation issues between my Next.js frontend (http://localhost:3000) and Laravel backend.
Here’s a summary of my original setup and the workaround that worked:
Frontend: Next.js app at http://localhost:3000 Backend: Laravel app accessed at 127.0.0.1:8081 using PHP I ran the following command to start the Laravel backend:
php -S 127.0.0.1:8081 -t public I used port 8081 because other common ports were reserved by Herd.